server {
listen 80;
server_name mydomain.com;
...
location /admin/ {
proxy_pass http://192.168.1.100:10080 ;
proxy_set_header Host $host:$server_port;
proxy_set_header Remote_Addr $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Nginx-Proxy true;
index index.html index.htm;
}
...
}
server {
listen 10080;
server_name mydomain.com;
...
location /admin/{
alias /xxx/xxx/admin/;
try_files $uri $uri/ /admin/index.html;
index index.html index.htm;
}
...
}
按照上面配置后,每次访问 http://mydomain.com/admin 时,都会重定向到 http://mydomain.com:10080/admin/。
因此,需要将 10080 这个端口去掉。
修改一级反向代理nginx的配置,如下:
server {
listen 80;
server_name mydomain.com;
...
location /admin/ {
proxy_pass http://192.168.1.100:10080 ;
proxy_redirect http://mydomain.com:10080/ /;
proxy_set_header Host $host:$server_port;
proxy_set_header Remote_Addr $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Nginx-Proxy true;
index index.html index.htm;
}
...
}
proxy_redirect 该指令用来修改被代理服务器返回的响应头中的Location头域和Refresh头域。