鍍金池/ 問答/Linux  數(shù)據(jù)庫/ nginx rewrite 添加base url

nginx rewrite 添加base url

這是我目前的設(shè)置,

location /jenkins {                                                                                                                                                                                  
                # First attempt to serve request as file, then                                                                                                                                                               # as directory, then fall back to displaying a 404.                                                                                                                                          
                # try_files $uri $uri/ =404;                                                                                                                                                                 
                include             /etc/nginx/proxy_params;                                                                                                                                                 
                proxy_pass          http://localhost:8080/;                                                                                                                                                  
                proxy_read_timeout  90s;                                                                                                                                                                     
                # Fix potential "It appears that your reverse proxy set up is broken" error.                                                                                                                 
                proxy_redirect      http://localhost:8080/ http://www.example.com/jenkins;                                                                                                                
        }

這樣設(shè)置我可以訪問http://www.example.com/jenkins,但是里面所有的requests都是導(dǎo)向http://www.example.com/的,實(shí)際上應(yīng)該導(dǎo)向http://www.example.com/jenkins,所以該如何寫rewrite rule,這樣只有/jenkins不會被改變,其他的url都在前面添加/jenkins/?

回答
編輯回答
深記你

你必須保持prefix一致,否則沒法簡單的反向代理。

如果你期望在nginx通過/jenkins訪問jenkins,那么你后端的jenkins訪問路徑必須也是/jenkins。至于這個prefix怎么改,官方文檔說的很清楚,我就不贅述了: https://wiki.jenkins.io/displ...

最后,官方文檔早有nginx反向代理參考: https://wiki.jenkins.io/displ...

2017年5月28日 06:38