nginx 反向代理 uri 重写
2021/7/18 7:05:43
本文主要是介绍nginx 反向代理 uri 重写,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
参考: https://serverfault.com/questions/379675/nginx-reverse-proxy-url-rewrite
有个需求
http://myserver:80/foo/bar 反向代理到后台端 http://localhost:3200/bar
两种方法,第二种是最正确的
第一种
location /foo { rewrite /foo/(.*) /$1 break; proxy_pass http://localhost:3200; proxy_redirect off; proxy_set_header Host $host; }
第二种
location /foo { proxy_pass http://localhost:3200/; }
upstream后面是否带反斜线很重要,
请注意proxy_pass指令末尾的附加/。NGINX将去掉匹配的前缀/foo,并将剩余的前缀传递给后端服务器的/路径。
因此,http://myserver:80/foo/bar 将发布到后端http://localhost:3200/bar.
这篇关于nginx 反向代理 uri 重写的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-29fail2ban nginx
- 2024-03-18install nginx proxy manager
- 2024-01-2444从零开始用Rust编写nginx,命令行参数的设计与解析及说明
- 2024-01-22比Nginx更好用的Gateway!
- 2024-01-17nginx daemon off
- 2023-12-30Nginx Vhost Traffic Status 是什么意思-icode9专业技术文章分享
- 2023-12-26使用nginx搭建creates.io镜像(稀疏索引)
- 2023-11-18centos7编译安装Nginx教程。
- 2023-11-02nginx启动命令和停止命令
- 2023-10-25Centos7系统Nginx负载均衡如何安装和配置?