django + uwsgi + nginx,python 文件下载而不是解析/执行

django + uwsgi + nginx,python 文件下载而不是解析/执行

我正在尝试启动并运行一个新的网络服务器。

php 文件可以正确解析,但 python 文件则不行。我将文件更改为 +x,但这没有效果。我的日志中没有出现 nginx 或 uwsgi 的任何错误

uwsgi --socket 0.0.0.0:8001 --protocol=http --uid www-data --gid www-data --ini /var/www/html/nerd/uwsgi.ini --wsgi-file /var/www/html/nerd/nerd/wsgi.py --chdir /var/www/html/nerd/




(nerds) root@guppy:/var/www/html# cat nerd/nerd/test.py 
# test.py
def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return [b"Hello World"] # python3

(书呆子)root@guppy:/var/www/html#

(nerds) root@guppy:/var/www/html# cat nerd/uwsgi.ini                 
[uwsgi]
module = wsgi:application
#module = wsgi
master = true
chdir = /var/www/html/nerd/
wsgi-file = /var/www/html/nerd/nerd/wsgi.py
uid = www-data
gid = www-data
vacuum = true
chmod-socket = 644
socket = 8001
#socket = /tmp/uwsgi.sock
plugins = python3
die-on-term = true
virtualenv = /var/www/html/nerds/
pythonpath = /var/www/html/nerds/lib/python3.5/dist-packages
pythonpath = /var/www/html/nerds/lib/python3.5
pythonpath = ./nerd
#module = django.core.handlers.wsgi:WSGIHandler()

(书呆子)root@guppy:/var/www/html#

(nerds) root@guppy:/var/www/html# cat nerd/nerd/wsgi.py                     
"""
WSGI config for nerd project.

It exposes the WSGI callable as a module-level variable named ``application``.

For more information on this file, see
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'nerd.settings')
#os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')

application = get_wsgi_application()


def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])
    return ["<h1 style='color:blue'>Hello There!</h1>"]

(书呆子)root@guppy:/var/www/html#

(nerds) root@guppy:/var/www/html# cat /etc/nginx/sites-available/default        
upstream django {
        #server unix:///tmp/uwsgi.sock; # for a file socket
        server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}


# Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.html index.htm index.php index.nginx-debian.html;

        server_name guppy.trade.com;

        location / {
                try_files $uri $uri/ =404;
                include     uwsgi_params;
        }

        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        }


}

如何让 nginx 正确解析脚本而不下载文件?

相关内容