Python Gunicorn和Nginx:504网关超时
我在Ubuntu服务器上运行一个使用gunicorn和nginx的Flask应用程序,但是当我加载页面时,我收到一个504网关超时错误。以下是我如何设置应用程序的: 我在Python Gunicorn和Nginx:504网关超时,python,nginx,flask,wsgi,gunicorn,Python,Nginx,Flask,Wsgi,Gunicorn,我在Ubuntu服务器上运行一个使用gunicorn和nginx的Flask应用程序,但是当我加载页面时,我收到一个504网关超时错误。以下是我如何设置应用程序的: 我在/etc/nginx/sites/中有一个名为app的文件,内容如下: # Redirect www.psflask.net to psflask.net server { server_name www.psflask.net; rewrite ^ http://psflask.net/ per
/etc/nginx/sites/
中有一个名为app
的文件,内容如下:
# Redirect www.psflask.net to psflask.net
server {
server_name www.psflask.net;
rewrite ^ http://psflask.net/ permanent;
}
# Handle requests to psflask.net on port 80
server {
listen 80;
server_name psflask.net;
# Handle all locations
location / {
# Pass the request to Gunicorn
proxy_pass http://127.0.0.1:8000;
# Set some HTTP headers so that our app knows where the
# request really came from
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
我使用以下方法创建了一个符号链接:
sudo ln -s /etc/nginx/sites-available/psflask.net /etc/nginx/sites-enabled/psflask.net
然后我用sudo服务重新启动nginx-restart
我经营gunicorn时:
gunicorn run:app -p psflask.pid -D
我尝试访问该页面,但加载需要一段时间,然后出现504网关超时错误。问题是什么?谢谢
编辑:
*重建的URL到:http://127.0.0.1:5000/
*在DNS缓存中找不到主机名
*正在尝试127.0.0.1。。。
*连接到127.0.0.1(127.0.0.1)端口5000(#0)
>GET/HTTP/1.1
>用户代理:curl/7.35.0
>主持人:127.0.0.1:5000
>接受:*/*
>
*HTTP 1.0,假设在正文之后关闭
如果您ping psflask.net,您是否获得ip?(你在一些域名服务器上注册过域名吗?)是的,域名确实指向服务器。否则,nginx错误甚至不会显示。如果您直接通过8000
端口请求应用程序,您会得到什么?如果您在本地计算机上运行应用程序,您可以导航到http://127.0.0.1:8000
在浏览器中。若您在远程服务器上运行它,则可以在命令行中运行:curl-vhttp://127.0.0.1:8000
。如果您得到相同的结果,问题在于您的应用程序,而不是nginx。由于某种原因,当我运行应用程序时,gunicorn使用port5000
和port8000
。如果我将nginx设置为侦听5000
,则504
错误消失,取而代之的是502坏网关错误
?@PavSidhu那么运行curl-v的结果是什么http://127.0.0.1:8000
?
* Rebuilt URL to: http://127.0.0.1:5000/
* Hostname was NOT found in DNS cache
* Trying 127.0.0.1...
* Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.35.0
> Host: 127.0.0.1:5000
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 200 OK
< Content-Type: text/html; charset=utf-8
< Content-Length: 125
< Server: Werkzeug/0.10.4 Python/2.7.6
< Date: Sat, 19 Sep 2015 14:43:37 GMT
<
<html>
<head>
<title>Home - microblog</title>
</head>
<body>
<h1>Hello, welcome to my site.</h1>
</body>
* Closing connection 0