运行nginx时,我无法访问gunicorn提供的Flask网站
我提前道歉,我对这一切都很陌生 我已经使用Flask socketio编写了一个应用程序。该网站在development服务器上运行良好,并通过localhost:5000访问它 我正在使用gunicorn为应用程序提供服务,运行时 gunicorn-绑定0.0.0.0:5000 wsgi:app 我可以通过0.0.0.0:5000访问该网站 现在我尝试使用systemd和nginx创建一个指向外部世界的访问点。nginx正在正常工作,但如果我尝试在浏览器中打开它,它将不再工作。我尝试了各种方法,使用服务器的IP地址,然后再次尝试0.0.0.0 我用systemd启动nginx来命名它。也许这是错的 systemctl状态nginx 我在这里不知所措,到目前为止,网上建议的任何解决方案都没有帮到我 我的申请结构是: /opt/myproj/proj_srv/application.py和wsgi.py等函数 /opt/myproj/proj_srv/functions/static所有静态文件,如index.html 我的项目的配置文件位于/etc/nginx/sites enabled/NEMO运行nginx时,我无法访问gunicorn提供的Flask网站,nginx,web,flask,gunicorn,systemd,Nginx,Web,Flask,Gunicorn,Systemd,我提前道歉,我对这一切都很陌生 我已经使用Flask socketio编写了一个应用程序。该网站在development服务器上运行良好,并通过localhost:5000访问它 我正在使用gunicorn为应用程序提供服务,运行时 gunicorn-绑定0.0.0.0:5000 wsgi:app 我可以通过0.0.0.0:5000访问该网站 现在我尝试使用systemd和nginx创建一个指向外部世界的访问点。nginx正在正常工作,但如果我尝试在浏览器中打开它,它将不再工作。我尝试了各种方法
listen 80;
server_name FRTM999.com www.FRTM999.com;
location/ {
proxy_pass http://127.0.0.1:8080;
}
location /static/ {
autoindex on;
alias /opt/NEMO/NEMO_Srv/functions/static/;
}
}
nginx配置文件
/etc/nginx/nginx.conf
events {
worker_connections 1024;
}
http {
sendfile on;
gzip on;
gzip_http_version 1.0;
gzip_proxied any;
gzip_min_length 500;
gzip_disable "MSIE [1-6]\.";
gzip_types text/plain text/xml text/css
text/comma-separated-values
text/javascript
pplication/x-javascript
application/atom+xml;
# Configuration containing list of application servers
upstream app_servers {
server 127.0.0.1:8080;
# server 127.0.0.1:8081;
# ..
}
# Configuration for Nginx
server {
# Running port
listen 80;
# Settings to serve static files
location ^~ /static/ {
# Example:
# root /full/path/to/application/static/file/dir;
root /opt/NEMO/NEMO_Srv/functions/static/;
}
Serve a static file (ex. favico)
# outside /static directory
location = /favico.ico {
root /opt/NEMO/NEMO_Srv/functions/static/favico.ico;
}
# Proxy connections to the application servers
# app_servers
location / {
proxy_pass http://app_servers;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
我的systemd服务文件
[Unit]
Description=uWSGI instance to serve myproject
After=network.target
[Service]
User=root
Group=www-data
WorkingDirectory=/opt/NEMO/NEMO_Srv/functions
ExecStart=/usr/bin/env gunicorn wsgi:app -b 0.0.0.0:5000
[Install]
WantedBy=multi-user.target
我不知道还能提供什么,请让我知道,如果我能让我的问题更清楚。也感谢您抽出时间!我非常感激 看看您的代码,nginx似乎只是在代理端口8080
upstream app_servers {
server 127.0.0.1:8080;
# server 127.0.0.1:8081;
}
location / {
proxy_pass http://127.0.0.1:8080;
}
然而,gunicorn似乎正在监听端口5000
ExecStart=/usr/bin/env gunicorn wsgi:app -b 0.0.0.0:5000
这两个应用程序不在同一个端口上通信,所以我认为这就是问题的原因