nginx 配置反代问题

可以用单纯的nginx语法 设置不同目录的 代理么?
例如

server
{
	listen 80;
	server_name xxx.com;
	location /baidu {
		proxy_redirect off;
		proxy_set_header Accept-Encoding "";
		proxy_set_header Host "baidu.com";
		proxy_set_header X-Real-IP $remote_addr;
		proxy_pass http://baidu.com;
}

访问xxx.com/baidu 会代理为 baidu.com

可以用set实现 访问 xxx.com/abc 代理为 abc.com 根据目录的不同自动代理不同的网站么?
该怎么实现呢?

阅读 3.2k
1 个回答

可否叙述详细点。。。不太明白你的需求是什么 。。如果你想要根据目录不同代理不同的网站 。。。这用nginx代理不太好吧 。。。你可以在你的程序里面写路由呀。。。。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题