在同一LAN服务器nginx上运行多个Web应用程序
我在局域网上提供2个docker容器,在端口5234上提供一个云服务器,在8080上提供另一个flask应用程序 我正在尝试使用nginx作为反向代理,在同一个ip上以不同的扩展运行它们。我的配置:在同一LAN服务器nginx上运行多个Web应用程序,nginx,nginx-reverse-proxy,nginx-location,Nginx,Nginx Reverse Proxy,Nginx Location,我在局域网上提供2个docker容器,在端口5234上提供一个云服务器,在8080上提供另一个flask应用程序 我正在尝试使用nginx作为反向代理,在同一个ip上以不同的扩展运行它们。我的配置: server { listen 80 default_server; server_name 192.168.1.23; location /web { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host;
server {
listen 80 default_server;
server_name 192.168.1.23;
location /web {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
access_log /var/log/nginx/flaskapp.access.log;
error_log /var/log/nginx/flaskapp.error.log;
}
location /cloud {
proxy_pass http://127.0.0.1:5234;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
access_log /var/log/nginx/nextcloud.access.log;
error_log /var/log/nginx/nextcloud.error.log;
}
}
但当访问192.168.1.23/web或192.168.1.23/cloud时,我得到了一个502坏网关
在flaskapp.error.log中:
connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.72, server: 192.168.1.23, request: "GET /web HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "192.168.1.23"
recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.1.72, server: 192.168.1.23, request: "GET /cloud HTTP/1.1", upstream: "http://127.0.0.1:5234/cloud", host: "192.168.1.23"
在nextcloud.error.log中:
connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.1.72, server: 192.168.1.23, request: "GET /web HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "192.168.1.23"
recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 192.168.1.72, server: 192.168.1.23, request: "GET /cloud HTTP/1.1", upstream: "http://127.0.0.1:5234/cloud", host: "192.168.1.23"
有没有办法像这样在同一ip上运行多个web应用程序或使用不同的端口?0.0.0不是有效的ip地址。请尝试127.0.0.1,它引用本地主机。 像这样:
proxy_pass http://127.0.0.1:8080;
更改了它,但我在尝试连接时仍然遇到502错误。您可以访问吗?删除尾随的/像这样的:proxy\u pass;添加了有关访问错误的更多信息。此外,我还试着移除拖带,但仍然不起作用。感谢您的建议,在该位置添加一个尾随斜杠。Location/web/和Location/cloud/因为它正在向上游发送路径