nginx proxypass监视链接

我试图设置Nginx使用proxy_pass转发请求到几个后端服务。

加载https://example.com/monit作品,但是页面内的链接是https://example.com/sshd而不是https://example.com/monit/sshd

我正在运行监视器5.2.5

我已经尝试过,没有下面的重写规则。

configuration文件;

proxy.conf

 location /monit { # rewrite /monit/(.*) /$1 break; proxy_pass http://localhost:2812/; include proxy.inc; } .... more entries .... 

/主启用的站点 –

 server { listen 443; server_name example.com; server_name_in_redirect off; include proxy.conf; ssl on; } 

proxy.inc

 proxy_connect_timeout 59s; proxy_send_timeout 600; proxy_read_timeout 600; proxy_buffer_size 64k; proxy_buffers 16 32k; proxy_pass_header Set-Cookie; proxy_redirect off; proxy_hide_header Vary; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; proxy_set_header Accept-Encoding ''; proxy_ignore_headers Cache-Control Expires; proxy_set_header Referer $http_referer; proxy_set_header Host $host; proxy_set_header Cookie $http_cookie; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Ssl on; proxy_set_header X-Forwarded-Proto https; 

我已经修改了重写规则,并确保清除caching,这是可行的;

 location /monit { rewrite ^/monit/(.*) /$1 break; proxy_pass http://localhost:2812/; include proxy.inc; } 

可悲的是,monit没有configuration允许它定义它的请求的BASE_URL,这意味着它总是直接在/下面添加它的服务,这会破坏你的/ monit代理匹配。 :(一个解决方法,但也许丑陋,是命名您的监控服务的方式,你可以匹配这个名字在Nginx中。

这是唯一的方法,你将能够做到这一点,除非你以某种方式破解monit源来更改URL为http:// localhost:2812 / monit /但我相信这是更难?

另一个select可能是,如果你可以在并行端口上运行nginx,并且只是重写访问这个端口的monit URL /端口,那么你可以重写/ proxypass整个/而不是/ monit这会使链接工作。 取决于你的公共IP和可用的端口,但应该做的伎俩?