簡體   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