这是我第一次部署Webapp,我真的需要您的帮助。我想在使用Nginx和Gunicorn的服务器上运行Flask Web应用程序。我找到了本教程,但无法正确运行该应用程序。我也尝试了其他在Internet上找到的方法,但是没有。这是我当前的/etc/nginx/sites-available/test.conf文件
server {
listen 80;
server_name hello.itu24.com;
root /home/ubuntu/test;
location / {
proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://127.0.0.1:8000;
}
}
相反,这是我的应用程序/home/ubuntu/test.py
from flask import Flask
from werkzeug.contrib.fixers import ProxyFix
app = Flask(__name__)
@app.route('/')
def test():
return "Hello world!"
app.wsgi_app = ProxyFix(app.wsgi_app)
if __name__ == '__main__':
app.run()
然后我运行以下命令
ubuntu@ace:~$ sudo service nginx reload
* Reloading nginx configuration nginx [ OK ]
ubuntu@ace:~$ sudo gunicorn -b h 127.0.0.1:8000 test:app
然后,如果我转到机器的IP地址,因为我正在从另一台机器进行连接,因此可以看到Nginx页面。但是,如果我在IP:8000地址中添加端口,则找不到页面。我究竟做错了什么?
Nginx可能有另一个默认端口为80的站点。请确保已从中删除了default.conf符号链接/etc/nginx/sites-enabled
。检查nginx.conf以确保其中没有配置服务器。
您的gunicorn命令看起来也不正确。您需要gunicorn -b 127.0.0.1:8000 test:app
在应用程序的目录中使用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句