nginx 代理时怎么更改 Remote Address 请求头
今天工作中遇到用 localhost 访问网站能访问后台 api,但是用本机IP地址后就拒绝访问,我怀疑是后台获取 Remote Address 然后设置白名单了只能 localhost 访问。
想用 nginx 更改 Remote Address
server {listen 8058;server_name localhost;location / {proxy_pass http://localhost:8080/; # 后端地址和端口proxy_set_header Host "localhost:8080";proxy_set_header Origin "http://localhost:8080";proxy_set_header Referer "http://localhost:8080";proxy_set_header Connection "keep-alive";proxy_set_header Cookie $http_cookie;}}
经过测试发现后端是用 Referer 这个字段做的白名单,更改这个头就可以通过验证了,如果需要别的头可以按这个方法设置就可以。