问题描述
nginx配置:
server { listen 80; server_name localhost; location /jenkins { proxy_set_headerHost $host:$server_port; proxy_set_headerX-Real-IP $remote_addr; proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_headerX-Forwarded-Proto $scheme; # Fix the 'It appears that your reverse proxy set up is broken' error. proxy_pass http://127.0.0.1:8081; proxy_read_timeout 90; } }
使用浏览器访问http://ip/jenkins,会跳转到http://ip/login?from=%2Fjenkins,出现404错误。
但使用下面的nginx配置
server { listen 80; server_name localhost; location / { proxy_set_headerHost $host:$server_port; proxy_set_headerX-Real-IP $remote_addr; proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_headerX-Forwarded-Proto $scheme; # Fix the 'It appears that your reverse proxy set up is broken' error. proxy_pass http://127.0.0.1:8081; proxy_read_timeout 90; } }
使用浏览器访问http://ip,会跳转到http://ip/login?from=%2Fjenkins,但是能正常访问,这是为什么呢?
想实现http://ip/jenkins这种访问方式,要怎样配置nginx?
问题解答
回答1:大概是这样
server{ location / {try_files $uri @jenkins; } location @jenkins {internal;proxy_pass http://127.0.0.1:8080; }}