开发者

Why does my python script download instead of run?

I am attempting to deploy my Django project on my shared web host using an .htaccess rewrite and a python script that runs FastCGI. I am using this method because I do not have the ability to change and Apache configuration. When I visit the site, instead of running the FastCGI script it downloads or displays the contents of the script file. I have made the script executable using chmod +x mysite.fcgi. I have placed the script in cgi-bin, but nothing works. The script will run from the command line.

.htaccess

AddHandler fcgid-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ cgi-bin/mysite.fcgi/$1 [QSA,L]

mysite.fcgi

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

# Add a custom Python path.
sys.path.insert(0, 开发者_高级运维"/home/jmjordan/.local/lib/python")
sys.path.insert(0, "/home/jmjordan/.local/lib/python/flup")


# Switch to the directory of your project. (Optional.)
# os.chdir("/home/user/myproject")

# Set the DJANGO_SETTINGS_MODULE environment variable.
os.environ['DJANGO_SETTINGS_MODULE'] = "jmjordan.settings"

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


I think you need:

<Files mysite.fcgi>
    SetHandler fastcgi-script
</Files>

somewhere in your Apache configuration. AddHandler just puts a handler in Apache's list of available handlers; you have to use SetHandler to use it.

This is probably a security measure to prevent someone from uploading a file with a .fcgi suffix and running arbitrary code on your server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜