一、location 反向代理方式
server {
listen 80;
server_name localhost;
location /test {proxy_pass http://localhost:8080/test2;}
location /test3 {proxy_pass http://localhost:8080/test3;}
}
二、rewrite 重定向
其中重定向外部地址的时候容易丢失post参数
以下是不关于参数的几种配置,直接看结果
rewrite ^/test.php /new permanent; //重写向带参数的地址
rewrite ^/test.php /new? permanent; //重定向后不带参数
rewrite ^/test.php /new?id=$arg_id? permanent; //重定向后带指定的参数
可以根据不同的域名配置到同一个服务器的不同端口
server {
listen 80;
server_name localhost;
#rewrite "^/test(.*)$" http://localhost:8080/test2 permanent;
}
本文介绍了Nginx的location反向代理和rewrite重定向两种配置方法。通过示例展示了如何将不同请求路径代理到不同服务器端口,并探讨了重定向时如何处理URL参数的问题。了解这些技巧有助于优化网站的服务器架构和路由管理。
1万+

被折叠的 条评论
为什么被折叠?



