这是我目前的设置,
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;
}
这样设置我可以访问http://www.example.com/jenkins,但是里面所有的requests都是导向http://www.example.com/的,实际上应该导向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...