我正在尝试为客户端到服务器配置 Nginx 反向代理。服务器正在为客户端监听端口 80 和 55555。我只能传递到端口 80,如何重定向到 2 个不同的端口?提前致谢。
server {
listen 80;
server_name 192.168.72.100;
return 301 https://192.168.72.100; }
server {
listen 443 ;
server_name 192.168.72.100;
# SSL config
ssl on;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_session_cache shared:SSL:20m;
ssl_session_timeout 4h;
access_log /temp/nginx/log/access.log;
error_log /temp/nginx/log/error.log error;
set $upstream 192.168.72.135;
location / {
proxy_pass_header Authorization;
proxy_pass http://$upstream;
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_http_version 1.1;
proxy_set_header Connection "";
proxy_buffering off;
client_max_body_size 0;
proxy_read_timeout 36000s;
proxy_redirect off;
proxy_ssl_session_reuse off;
}
答案1
文档位于http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass显示如何为上游指定端口的示例:
proxy_pass http://localhost:8000/uri/;
因此,如果您想将请求转发到 192.168.72.135 端口 55555,请使用:
proxy_pass http://192.168.72.135:5555;