我有以下 nginx 配置文件,用于从同一台机器为 gitbucket 和 jenkins 提供服务。我可以访问 bitbucket,但当我输入 domain/jenkins/ 时,我最终进入了 gitbuckets 404 页面。我的配置有什么问题?
server {
listen 80;
return 301 https://$host$request_uri;
}
server {
listen 443;
ssl_certificate /etc/nginx/cert.crt;
ssl_certificate_key /etc/nginx/cert.key;
ssl on;
ssl_session_cache builtin:1000 shared:SSL:10m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
ssl_prefer_server_ciphers on;
location /jenkins/ {
proxy_pass http://127.0.0.1:8081;
}
location / {
# Fix the “It appears that your reverse proxy set up is broken" error.
proxy_pass http://127.0.0.1:8080;
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_connect_timeout 150;
proxy_send_timeout 100;
proxy_read_timeout 100;
proxy_buffers 4 32k;
}
}
答案1
查看http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass。看起来你必须做这样的事:
位置 ~ ^/jenkins(.*)$ { proxy_pass http://127.0.0.1:8081; }
位置 ~ ^/(.*)$ {...如您所见...}