我在局域網上提供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;
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壞網關。
In 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"
In nextcloud.error.log:
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.0不是有效的IP地址。試試127.0.0.1,它指向本地主機。這樣地: