我已经在 Arch Linux 板上问过这个问题,但没有得到任何答复。所以我在这里试试运气:
我正在尝试在我的 Arch Linux 服务器上设置 nginx + gunicorn 以运行多个 Flask 应用程序。但是,我似乎未能以正确的方式配置 nginx。当我刚刚启动并运行一个 Flask 应用程序时,一切似乎都运行良好。我在 /etc/nginx/nginx.conf 中包含了 /etc/nginx/sites-available 和 /etc/nginx/sites-enabled 。我在 /etc/nginx/sites/available 中创建了一个文件“flask_settings”并将其链接到 /etc/nginx/sites-enabled。该文件如下所示:
server {
location /{
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个文件夹,其中包含我在虚拟环境中使用 gunicorn 运行的 Flask 应用程序(示例应用程序,hellp.py)。我只是使用它运行它
gunicorn hello:app
Run Code Online (Sandbox Code Playgroud)
如果我访问我的服务器 IP,我可以访问该文件和不同的路由。现在我尝试设置另一个应用程序,在 /etc/nginx/sites-enabled 中创建另一个名为flask2的文件。它看起来像这样:
server {
location /hello {
proxy_pass http://127.0.0.1:8001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Run Code Online (Sandbox Code Playgroud)
然后我尝试在它自己的虚拟环境中运行该应用程序
gunicorn --bind 127.0.0.1:8001 hello:app
Run Code Online (Sandbox Code Playgroud)
当我之后重新启动 nginx 时,我仍然可以访问第一个应用程序及其所有路由,但是如果我尝试通过输入我的服务器 IP + 路由器(在“/”之后)来访问另一个应用程序,nginx 总是告诉我,无法找到这些站点。我在这里错过了什么吗?任何帮助都受到高度赞赏。提前致谢!