我有一个应用程序,端点为 http://localhost:3000/seller/,我使用 nginxproxy_pass
server {
include default_proxy_headers;
listen 80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name domain.my;
location /seller {
proxy_buffering off;
proxy_pass http://localhost:3000;
}
location /seller/api {
rewrite /seller/(.*) /$1 break;
proxy_pass http://localhost:5000;
proxy_buffering off;
}
}
它的工作方式与我预期的一样https://domain.my/seller/- 没关系。
如果我尝试使用https://domain.my/seller(末尾没有“/”斜杠)它会重定向到https://domain.my:3000/卖家/。
如何禁用重定向到“:3000”端口?我希望它只作为https://domain.my/seller/(末尾带有 / 斜线)。
答案1
好的。如果我理解正确的话,请看一下。如果您使用会怎么样upstream
?端口号在每个端口内移动,upstream
以便您proxy_pass
通过别名访问它们。
upstream backend1 {
# PHP-CGI GATEWAY 1 - listening on IPv4 & Port...
server 127.0.0.1:3000 weight=3 max_fails=1 fail_timeout=1s;
} # END upstream backend1
upstream backend2 {
# PHP-CGI GATEWAY 2 - listening on IPv4 & Port...
server 127.0.0.1:5000 weight=3 max_fails=1 fail_timeout=1s;
} # END upstream backend2
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name *.example1.com;
root /var/www/example1.com/public;
index index.html;
location /seller {
proxy_pass http://backend1;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
# Proxy headers
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
# Proxy timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
location /seller/api {
proxy_pass http://backend2;
proxy_http_version 1.1;
proxy_cache_bypass $http_upgrade;
# Proxy headers
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
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;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
# Proxy timeouts
proxy_connect_timeout 60s;
proxy_send_timeout 60s;
proxy_read_timeout 60s;
}
}