Pregunta

En primer lugar, aquí está mi guión:

#!/usr/bin/python
import sys, os

sys.path.append('/home/username/python')
sys.path.append("/home/username/python/flup")
sys.path.append("/home/username/python/django")
# more path stuff

os.environ['DJANGO_SETTINGS_MODULE'] = "project.settings"

from django.core.servers.fastcgi import runfastcgi
runfastcgi(method="threaded", daemonize="false")

Como se describió aquí .

Y aquí está el error que recibo al intentar ejecutarlo desde el shell:

WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
Status: 404 NOT FOUND
Content-Type: text/html


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<!-- more html which looks to be the correct output -->

Mi pregunta es, ¿por qué FastCGI no pasa esos parámetros automáticamente? ¿Qué estoy haciendo mal? Ejecutar el script desde mi servidor web solo me da un error interno del servidor.


En lugar de las dos últimas líneas de mi script, puedo usar

from flup.server.fcgi import WSGIServer
from django.core.handlers.wsgi import WSGIHandler
WSGIServer(WSGIHandler()).run()

Pero sigo teniendo exactamente el mismo error ...

¿Fue útil?

Solución

Lo resolvió. Este archivo .htaccess hizo el truco, por cualquier razón. Juro que intenté todo esto antes ...

AddHandler fcgid-script .fcgi
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(adminmedia/.*)$ - [L]
RewriteCond %{REQUEST_URI} !(cgi-bin/myproject.fcgi)
RewriteRule ^(.*)$ cgi-bin/myproject.fcgi/$1 [L]

Otros consejos

El script espera que esos parámetros se pasen como variables de entorno. Ya que no están presentes en su entorno de shell, y el script no se está ejecutando en el entorno de apache fastcgi (que los proporciona), se queja.

¿Tiene acceso a los registros de errores de Apache? ¿Qué dicen?

¿Tu host tiene soporte mod_wsgi? Si es así, podrías usar el controlador wsgi de Django:

import sys
import os

base = os.path.dirname(os.path.abspath(__file__)) + '/..'
sys.path.append(base)

os.environ['DJANGO_SETTINGS_MODULE'] = 'yourproject.settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

Se pueden encontrar más instrucciones en wiki de modwsgi , y el < a href = "http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/" rel = "nofollow noreferrer"> Django docs .

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top