我正在尝试在 Linode.com 上使用 Nginx 托管一个应用程序,但是在 uWSGI 配置上遇到了困难。
我用过“入门”指南和“在 Ubuntu 12.04 (Precise Pangolin) 上使用 uWSGI 和 nginx 的 WSGI”指南并且我已经成功部署了 Nginx(在浏览器中收到了 Nginx 欢迎消息)。
虽然以上教程适用于 Ubuntu 12.04,但我使用的是 14.04。
当我进入 uWSGI 配置和“Hello World”Python 应用程序时,问题就开始了。进入location /
浏览器后,返回结果显示Failed to load resource: the server responded with a status of 500 (Internal Server Error)
服务器 error.log 中没有任何记录。location /static
但运行正常,文件传输没有任何问题。
我尝试了很多方法,并在 Google 和 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
/etc/nginx/sites-enabled/example.com
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;
}
}
/etc/uwsgi/apps-enabled/example.com.xml
<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>
/srv/www/example.com/application/wsgi_configuration_module.py
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!'
last access log
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"
only error log I've got only one time when trying to fix this
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/"