Python Nginx和uWSGI的内部服务器错误

Python Nginx和uWSGI的内部服务器错误,python,ubuntu,nginx,wsgi,uwsgi,Python,Ubuntu,Nginx,Wsgi,Uwsgi,我正在尝试在Linode.com上使用Nginx托管一个应用程序,但是我在uWSGI配置上很早就被卡住了 我已经使用并成功部署了Nginx(在浏览器中收到Nginx欢迎消息) 虽然上面的教程是针对Ubuntu12.04的,但我已经使用了14.04 当我进入uWSGI配置和“Hello World”Python应用程序时,问题就开始了。在浏览器中转到location/返回加载资源失败:服务器响应状态为500(内部服务器错误),并且在server Error.log中未记录任何内容位置/static

我正在尝试在Linode.com上使用Nginx托管一个应用程序,但是我在uWSGI配置上很早就被卡住了

我已经使用并成功部署了Nginx(在浏览器中收到Nginx欢迎消息)

虽然上面的教程是针对Ubuntu12.04的,但我已经使用了14.04

当我进入uWSGI配置和“Hello World”Python应用程序时,问题就开始了。在浏览器中转到
location/
返回
加载资源失败:服务器响应状态为500(内部服务器错误)
,并且在server Error.log中未记录任何内容<代码>位置/static工作,并且可以不挂起故障地为文件服务

我尝试了很多东西,并广泛地寻找谷歌和Stackoverflow的修复方案,但什么都没有,我现在有点沮丧

谢谢你的帮助

这里是我的配置文件(我已经隐藏了我的域和ip):

/etc/hosts

127.0.0.1   localhost
127.0.1.1   ubuntu
XX.XX.XX.XXX mars

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
server {
    listen      80;
    server_name $hostname;
    access_log  /srv/www/example.com/logs/access.log;
    error_log   /srv/www/example.com/logs/error.log;

    location / {
        #uwsgi_pass 127.0.0.1:9001;
        uwsgi_pass  unix:///run/uwsgi/app/example.com/example.com.socket;
        include     uwsgi_params;
        uwsgi_param UWSGI_SCHEME $scheme;
        uwsgi_param SERVER_SOFTWARE nginx/$nginx_version;
    }

    location /static {
        root        /srv/www/example.com/public_html/;
        index       index.html index.htm;
    }

}
<uwsgi>
    <plugin>python</plugin>
    <socket>/run/uwsgi/app/example.com/example.com.socket</socket>
    <pythonpath>/srv/www/example.com/application/</pythonpath>
    <app mountpoint="/">

        <script>wsgi_configuration_module</script>

    </app>
    <master/>
    <processes>4</processes>
    <harakiri>60</harakiri>
    <reload-mercy>8</reload-mercy>
    <cpu-affinity>1</cpu-affinity>
    <stats>/tmp/stats.socket</stats>
    <max-requests>2000</max-requests>
    <limit-as>512</limit-as>
    <reload-on-as>256</reload-on-as>
    <reload-on-rss>192</reload-on-rss>
    <no-orphans/>
    <vacuum/>
</uwsgi>
import os
import sys
sys.path.append('/srv/www/example.com/application')
os.environ['PYTHON_EGG_CACHE'] = '/srv/www/example.com/.python-egg'

def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])

    return 'Hello world!'
XX.XX.XX.XXX - - [05/Jul/2015:10:03:37 -0400] "GET / HTTP/1.1" 500 32 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
XX.XX.XX.XXX - - [05/Jul/2015:10:03:38 -0400] "GET /favicon.ico HTTP/1.1" 500 32 "http://example.com/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
2015/07/05 08:49:06 [crit] 25301#0: *17 connect() to unix:///run/uwsgi/app/example.com/example.com.socket failed (2: No such file or directory) while connecting to upstream, client: XX.XX.XX.XXX, server: mars, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///run/uwsgi/app/example.com/example.com.socket:", host: "example.com"
2015/07/05 08:49:07 [crit] 25301#0: *17 connect() to unix:///run/uwsgi/app/example.com/example.com.socket failed (2: No such file or directory) while connecting to upstream, client: XX.XX.XX.XXX, server: mars, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:///run/uwsgi/app/example.com/example.com.socket:", host: "example.com", referrer: "http://example.com/"
/etc/nginx/sites enabled/example.com

127.0.0.1   localhost
127.0.1.1   ubuntu
XX.XX.XX.XXX mars

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
server {
    listen      80;
    server_name $hostname;
    access_log  /srv/www/example.com/logs/access.log;
    error_log   /srv/www/example.com/logs/error.log;

    location / {
        #uwsgi_pass 127.0.0.1:9001;
        uwsgi_pass  unix:///run/uwsgi/app/example.com/example.com.socket;
        include     uwsgi_params;
        uwsgi_param UWSGI_SCHEME $scheme;
        uwsgi_param SERVER_SOFTWARE nginx/$nginx_version;
    }

    location /static {
        root        /srv/www/example.com/public_html/;
        index       index.html index.htm;
    }

}
<uwsgi>
    <plugin>python</plugin>
    <socket>/run/uwsgi/app/example.com/example.com.socket</socket>
    <pythonpath>/srv/www/example.com/application/</pythonpath>
    <app mountpoint="/">

        <script>wsgi_configuration_module</script>

    </app>
    <master/>
    <processes>4</processes>
    <harakiri>60</harakiri>
    <reload-mercy>8</reload-mercy>
    <cpu-affinity>1</cpu-affinity>
    <stats>/tmp/stats.socket</stats>
    <max-requests>2000</max-requests>
    <limit-as>512</limit-as>
    <reload-on-as>256</reload-on-as>
    <reload-on-rss>192</reload-on-rss>
    <no-orphans/>
    <vacuum/>
</uwsgi>
import os
import sys
sys.path.append('/srv/www/example.com/application')
os.environ['PYTHON_EGG_CACHE'] = '/srv/www/example.com/.python-egg'

def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])

    return 'Hello world!'
XX.XX.XX.XXX - - [05/Jul/2015:10:03:37 -0400] "GET / HTTP/1.1" 500 32 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
XX.XX.XX.XXX - - [05/Jul/2015:10:03:38 -0400] "GET /favicon.ico HTTP/1.1" 500 32 "http://example.com/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
2015/07/05 08:49:06 [crit] 25301#0: *17 connect() to unix:///run/uwsgi/app/example.com/example.com.socket failed (2: No such file or directory) while connecting to upstream, client: XX.XX.XX.XXX, server: mars, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///run/uwsgi/app/example.com/example.com.socket:", host: "example.com"
2015/07/05 08:49:07 [crit] 25301#0: *17 connect() to unix:///run/uwsgi/app/example.com/example.com.socket failed (2: No such file or directory) while connecting to upstream, client: XX.XX.XX.XXX, server: mars, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:///run/uwsgi/app/example.com/example.com.socket:", host: "example.com", referrer: "http://example.com/"
/etc/uwsgi/apps enabled/example.com.xml

127.0.0.1   localhost
127.0.1.1   ubuntu
XX.XX.XX.XXX mars

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
server {
    listen      80;
    server_name $hostname;
    access_log  /srv/www/example.com/logs/access.log;
    error_log   /srv/www/example.com/logs/error.log;

    location / {
        #uwsgi_pass 127.0.0.1:9001;
        uwsgi_pass  unix:///run/uwsgi/app/example.com/example.com.socket;
        include     uwsgi_params;
        uwsgi_param UWSGI_SCHEME $scheme;
        uwsgi_param SERVER_SOFTWARE nginx/$nginx_version;
    }

    location /static {
        root        /srv/www/example.com/public_html/;
        index       index.html index.htm;
    }

}
<uwsgi>
    <plugin>python</plugin>
    <socket>/run/uwsgi/app/example.com/example.com.socket</socket>
    <pythonpath>/srv/www/example.com/application/</pythonpath>
    <app mountpoint="/">

        <script>wsgi_configuration_module</script>

    </app>
    <master/>
    <processes>4</processes>
    <harakiri>60</harakiri>
    <reload-mercy>8</reload-mercy>
    <cpu-affinity>1</cpu-affinity>
    <stats>/tmp/stats.socket</stats>
    <max-requests>2000</max-requests>
    <limit-as>512</limit-as>
    <reload-on-as>256</reload-on-as>
    <reload-on-rss>192</reload-on-rss>
    <no-orphans/>
    <vacuum/>
</uwsgi>
import os
import sys
sys.path.append('/srv/www/example.com/application')
os.environ['PYTHON_EGG_CACHE'] = '/srv/www/example.com/.python-egg'

def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])

    return 'Hello world!'
XX.XX.XX.XXX - - [05/Jul/2015:10:03:37 -0400] "GET / HTTP/1.1" 500 32 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
XX.XX.XX.XXX - - [05/Jul/2015:10:03:38 -0400] "GET /favicon.ico HTTP/1.1" 500 32 "http://example.com/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
2015/07/05 08:49:06 [crit] 25301#0: *17 connect() to unix:///run/uwsgi/app/example.com/example.com.socket failed (2: No such file or directory) while connecting to upstream, client: XX.XX.XX.XXX, server: mars, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///run/uwsgi/app/example.com/example.com.socket:", host: "example.com"
2015/07/05 08:49:07 [crit] 25301#0: *17 connect() to unix:///run/uwsgi/app/example.com/example.com.socket failed (2: No such file or directory) while connecting to upstream, client: XX.XX.XX.XXX, server: mars, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:///run/uwsgi/app/example.com/example.com.socket:", host: "example.com", referrer: "http://example.com/"
上次访问日志

127.0.0.1   localhost
127.0.1.1   ubuntu
XX.XX.XX.XXX mars

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
server {
    listen      80;
    server_name $hostname;
    access_log  /srv/www/example.com/logs/access.log;
    error_log   /srv/www/example.com/logs/error.log;

    location / {
        #uwsgi_pass 127.0.0.1:9001;
        uwsgi_pass  unix:///run/uwsgi/app/example.com/example.com.socket;
        include     uwsgi_params;
        uwsgi_param UWSGI_SCHEME $scheme;
        uwsgi_param SERVER_SOFTWARE nginx/$nginx_version;
    }

    location /static {
        root        /srv/www/example.com/public_html/;
        index       index.html index.htm;
    }

}
<uwsgi>
    <plugin>python</plugin>
    <socket>/run/uwsgi/app/example.com/example.com.socket</socket>
    <pythonpath>/srv/www/example.com/application/</pythonpath>
    <app mountpoint="/">

        <script>wsgi_configuration_module</script>

    </app>
    <master/>
    <processes>4</processes>
    <harakiri>60</harakiri>
    <reload-mercy>8</reload-mercy>
    <cpu-affinity>1</cpu-affinity>
    <stats>/tmp/stats.socket</stats>
    <max-requests>2000</max-requests>
    <limit-as>512</limit-as>
    <reload-on-as>256</reload-on-as>
    <reload-on-rss>192</reload-on-rss>
    <no-orphans/>
    <vacuum/>
</uwsgi>
import os
import sys
sys.path.append('/srv/www/example.com/application')
os.environ['PYTHON_EGG_CACHE'] = '/srv/www/example.com/.python-egg'

def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])

    return 'Hello world!'
XX.XX.XX.XXX - - [05/Jul/2015:10:03:37 -0400] "GET / HTTP/1.1" 500 32 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
XX.XX.XX.XXX - - [05/Jul/2015:10:03:38 -0400] "GET /favicon.ico HTTP/1.1" 500 32 "http://example.com/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
2015/07/05 08:49:06 [crit] 25301#0: *17 connect() to unix:///run/uwsgi/app/example.com/example.com.socket failed (2: No such file or directory) while connecting to upstream, client: XX.XX.XX.XXX, server: mars, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///run/uwsgi/app/example.com/example.com.socket:", host: "example.com"
2015/07/05 08:49:07 [crit] 25301#0: *17 connect() to unix:///run/uwsgi/app/example.com/example.com.socket failed (2: No such file or directory) while connecting to upstream, client: XX.XX.XX.XXX, server: mars, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:///run/uwsgi/app/example.com/example.com.socket:", host: "example.com", referrer: "http://example.com/"
唯一错误日志我在尝试修复此问题时只有一次

127.0.0.1   localhost
127.0.1.1   ubuntu
XX.XX.XX.XXX mars

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
server {
    listen      80;
    server_name $hostname;
    access_log  /srv/www/example.com/logs/access.log;
    error_log   /srv/www/example.com/logs/error.log;

    location / {
        #uwsgi_pass 127.0.0.1:9001;
        uwsgi_pass  unix:///run/uwsgi/app/example.com/example.com.socket;
        include     uwsgi_params;
        uwsgi_param UWSGI_SCHEME $scheme;
        uwsgi_param SERVER_SOFTWARE nginx/$nginx_version;
    }

    location /static {
        root        /srv/www/example.com/public_html/;
        index       index.html index.htm;
    }

}
<uwsgi>
    <plugin>python</plugin>
    <socket>/run/uwsgi/app/example.com/example.com.socket</socket>
    <pythonpath>/srv/www/example.com/application/</pythonpath>
    <app mountpoint="/">

        <script>wsgi_configuration_module</script>

    </app>
    <master/>
    <processes>4</processes>
    <harakiri>60</harakiri>
    <reload-mercy>8</reload-mercy>
    <cpu-affinity>1</cpu-affinity>
    <stats>/tmp/stats.socket</stats>
    <max-requests>2000</max-requests>
    <limit-as>512</limit-as>
    <reload-on-as>256</reload-on-as>
    <reload-on-rss>192</reload-on-rss>
    <no-orphans/>
    <vacuum/>
</uwsgi>
import os
import sys
sys.path.append('/srv/www/example.com/application')
os.environ['PYTHON_EGG_CACHE'] = '/srv/www/example.com/.python-egg'

def application(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])

    return 'Hello world!'
XX.XX.XX.XXX - - [05/Jul/2015:10:03:37 -0400] "GET / HTTP/1.1" 500 32 "-" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
XX.XX.XX.XXX - - [05/Jul/2015:10:03:38 -0400] "GET /favicon.ico HTTP/1.1" 500 32 "http://example.com/" "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36"
2015/07/05 08:49:06 [crit] 25301#0: *17 connect() to unix:///run/uwsgi/app/example.com/example.com.socket failed (2: No such file or directory) while connecting to upstream, client: XX.XX.XX.XXX, server: mars, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:///run/uwsgi/app/example.com/example.com.socket:", host: "example.com"
2015/07/05 08:49:07 [crit] 25301#0: *17 connect() to unix:///run/uwsgi/app/example.com/example.com.socket failed (2: No such file or directory) while connecting to upstream, client: XX.XX.XX.XXX, server: mars, request: "GET /favicon.ico HTTP/1.1", upstream: "uwsgi://unix:///run/uwsgi/app/example.com/example.com.socket:", host: "example.com", referrer: "http://example.com/"

我不明白它是什么/etc/nginx/sites enabled/dev.host.in?如何或为什么*.in? 我想你应该试试

step 1.

create project.ini file

# django_project.ini file
[uwsgi]

# Django-related settings
# the base directory (full path)
chdir           = /home/username/django_project
# Django's wsgi file
module          = blog.wsgi
# the virtualenv (full path)
home            = /home/username/Env/project
# process-related settings
master          = true
pidfile         = /tmp/proj_uwsgi.pid
# maximum number of worker processes
processes       = 5
# the socket
socket          = :8001
# ... with appropriate permissions - may be needed
# chmod-socket    = 664
# clear environment on exit
vacuum           = true
# background the process
daemonize        = /home/username/django_project/error_uwsgi.log


step 2.

create mysite.conf in nginx, vim /etc/nginx/conf.d/mysite.conf

upstream django {
    #server unix:///home/username/django_project/djproj.sock; # for a file socket
    server 127.0.0.1:8001; # for a web port socket (we'll use this first)
}

# configuration of the server
server {
    # the port your site will be served on
    listen      80;
    # the domain name it will serve for
    server_name localhost mysite.com www.mysite.com; # substitute your machine's IP address or FQDN
    charset     utf-8;

    # max upload size
    client_max_body_size 75M;   # adjust to taste

    # Django media
    location /media  {        alias /home/username/django_project/media;  # your Django project's media files - amend as required
    }

    location /static {        alias /home/username/django_project/static; # your Django project's static files - amend as required
    }

    # Finally, send all non-media requests to the Django server.
    location / {
        uwsgi_pass  127.0.0.1:8001;#project;        
        include     /home/username/django_project/uwsgi_params; # the uwsgi_params file you installed
    }
}



step 3.

ln -s /etc/nginx/uwsgi_params /home/username/django_project/

step 4.

uwsgi --ini django_project.ini

uwsgi --stop /tmp/proj_uwsgi.pid
uwsgi --reload /tmp/proj_uwsgi.pid

你的settings.py文件在哪里?我甚至没有进入Django安装程序。问题是,即使是我的hello world uWSGI应用程序也无法工作。
wsgi\u configuration\u module.py
。中的一个是印度域(回想起来,我可能应该将其更改为.com以避免混淆)。谢谢你的回答,我会很快尝试这个解决方案。