我在Ubuntu服务器上使用gunicorn和nginx运行Flask应用程序,但是当我加载页面时,我收到了504 Gateway Time-Out错误。这就是我在this之后设置应用程序的方法:
我在app
中有一个名为/etc/nginx/sites-available/
的文件,其中包含以下内容:
# 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 service nginx restart
我用手枪:
gunicorn run:app -p psflask.pid -D
我尝试访问该页面但是,加载需要一段时间,然后我得到504网关超时错误。有什么问题?感谢。
编辑:
* 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