如何使用 Nginx 和 Docker 代理应用程序
How to proxy applications with Nginx and Docker
我收到 nginx 的 5#5: *23 upstream timed out (110: Connection timed out) while connecting to upstream, client:
错误。
我已阅读并应用了 Nginx reverse proxy causing 504 Gateway Timeout 问题。但是我的情况略有不同,因为我有三个端点要代理。
我的nginx.conf:
worker_processes 1;
events { worker_connections 1024; }
http {
server {
listen 80;
listen [::]:80;
server_name rollcall;
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass "http://[hostip]:8080/api";
}
location /api/attendance {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass "http://[hostip]:8000/api";
}
location / {
include /etc/nginx/mime.types;
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
我的“/”和具有 port:8080 代理的应用程序正如预期的那样,但是我的具有 port:8000 的应用程序没有代理,并得到上述超时异常。如果我尝试使用 port:8000 请求应用程序,应用程序将按预期工作。
什么可能导致上述超时,我应该如何更改我的 conf 文件?
问题不是 Nginx 或 Docker 相关的问题。端口 8000 未在应用程序 Droplet 上打开。
我收到 nginx 的 5#5: *23 upstream timed out (110: Connection timed out) while connecting to upstream, client:
错误。
我已阅读并应用了 Nginx reverse proxy causing 504 Gateway Timeout 问题。但是我的情况略有不同,因为我有三个端点要代理。
我的nginx.conf:
worker_processes 1;
events { worker_connections 1024; }
http {
server {
listen 80;
listen [::]:80;
server_name rollcall;
location /api {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass "http://[hostip]:8080/api";
}
location /api/attendance {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass "http://[hostip]:8000/api";
}
location / {
include /etc/nginx/mime.types;
root /usr/share/nginx/html;
index index.html index.htm;
try_files $uri $uri/ /index.html =404;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
我的“/”和具有 port:8080 代理的应用程序正如预期的那样,但是我的具有 port:8000 的应用程序没有代理,并得到上述超时异常。如果我尝试使用 port:8000 请求应用程序,应用程序将按预期工作。
什么可能导致上述超时,我应该如何更改我的 conf 文件?
问题不是 Nginx 或 Docker 相关的问题。端口 8000 未在应用程序 Droplet 上打开。