繁体   English   中英

Nginx代理到本地主机上的应用程序

[英]Nginx proxy to application on localhost

我在端口80上设置了Nginx Web服务器。我的(SonarQube)应用程序在端口9000上运行。当我请求http://www.example.com/sonar/时,我希望重定向到Sonar,因此我将其添加到了我的Nginx的配置:

location /sonar/ {
    proxy_pass  http://127.0.0.1:9000/;

    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_read_timeout  1800;
    proxy_connect_timeout 1800;
    auth_basic "Restricted";
    auth_basic_user_file /etc/nginx/.htpasswd;
}

但是,当我转到http://www.example.com/sonar/时 ,此页面上的每个链接都转到http://www.example.com/而不是http://www.example.com/sonar/ 因此,样式表,css脚本和链接已损坏。 我怎样才能解决这个问题? 我尝试rewrite ,但似乎无法正常工作。

问题出在proxy_pass行中。 在您的情况下,应为:

proxy_pass  http://127.0.0.1:9000;

但不是:

proxy_pass  http://127.0.0.1:9000/;

proxy_pass指令中,如果您指定的URI是/ ,则匹配的URI /sonar/将替换为指定的/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM