准备反向代理的网站:www.a.com
目标网站:www.b.com
进入nginx的配置文件:
添加如下:
1 location / { 2 proxy_set_header X-Real-IP $remote_addr; 3 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 4 proxy_pass http://www.a.com; 5 }
访问www.a.com后会直接跳转到www.b.com
如果想访问www.a.com/a/调准到www.b.com/b/
进入nginx的配置文件:
添加如下:
1 location /a/ { 2 proxy_set_header X-Real-IP $remote_addr; 3 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 4 proxy_pass http://www.b.com/b/; 5 }
其他例子就不一一列举了,可以参考nginx的官方文档,链接:https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/#
原文地址:https://www.cnblogs.com/steven1995/p/9797689.html
时间: 2024-10-17 13:11:50