【发布时间】:2017-02-14 16:01:07
【问题描述】:
从昨天开始,我已经阅读了很多关于这个问题的说明,但它们都有类似的步骤。但是我一步一步地跟着,但仍然无法得到一切。
其实我可以让 Flask+Gunicorn+supervisor 工作,但是 Nginx 不能正常工作。
我使用 SSH 连接我的远程云服务器,但我没有在我的计算机上部署站点。
Nginx 安装正确,因为当我通过域名(又名example.com)访问该站点时,它会显示 Nginx 欢迎页面。
我用supervisor启动Gunicorn,配置是
[program:myapp]
command=/home/fh/test/venv/bin/gunicorn -w4 -b 0.0.0.0:8000 myapp:app
directory=/home/fh/test
startsecs=0
stopwaitsecs=0
autostart=false
autorestart=false
stdout_logfile=/home/fh/test/log/gunicorn.log
stderr_logfile=/home/fh/test/log/gunicorn.err
这里我将服务器绑定到端口 8000 和 我实际上并不知道 0.0.0.0 代表什么,但我认为这并不意味着本地主机,因为我可以访问通过 http://example.com:8000 的网站,它运行良好。
然后我尝试使用 Nginx 作为代理服务器。
我删除了 /etc/nginx/sites-available/default' and '/etc/nginx/sites-enabled/default/ 并创建了 /etc/nginx/sites-available/test.com 和 /etc/nginx/sites-enabled/test.com 并将它们符号链接。
test.com
server {
server_name www.penguin-penpen.com;
rewrite ^ http://example/ permanent;
}
# Handle requests to example.com on port 80
server {
listen 80;
server_name example.com;
# 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;
}
}
据我了解,Nginx 所做的是当我访问 http://example.com 时,它会将我的请求传递给 http://example.com:8000。
我不太确定我应该在这里使用proxy_pass http://127.0.0.1:8000,因为我不知道Nginx是否应该将请求传递给本地主机但是我尝试将其更改为0.0.0.0:8000但它仍然没有不行。
谁能帮忙?
【问题讨论】:
标签: python nginx web flask server