Domanda

In primo luogo, ecco la mia sceneggiatura:

#!/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")

Come è stato descritto qui .

Ed ecco l'errore che ottengo quando provo a eseguirlo dalla 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 -->

La mia domanda è: perché quei parametri non vengono passati automaticamente da FastCGI? Che cosa sto facendo di sbagliato? L'esecuzione dello script dal mio server Web mi dà solo un errore interno del server.


Invece delle ultime due righe del mio script, posso usare

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

Ma ottengo sempre lo stesso errore esatto ...

È stato utile?

Soluzione

Risolto. Questo file .htaccess ha funzionato, per qualsiasi motivo. Giuro di aver provato tutto questo prima ...

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]

Altri suggerimenti

Lo script prevede che questi parametri vengano passati come variabili di ambiente. Dato che non sono presenti nel tuo ambiente shell e che lo script non è in esecuzione nell'ambiente apache fastcgi (che li fornisce), si lamenta.

Hai accesso ai log degli errori di Apache? Cosa dicono?

Il tuo host ha il supporto mod_wsgi? In tal caso, è possibile utilizzare il gestore wsgi di 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()

Ulteriori istruzioni sono disponibili nel modwsgi wiki e nel < a href = "http://docs.djangoproject.com/en/dev/howto/deployment/modwsgi/" rel = "nofollow noreferrer"> Django docs .

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top