nginx配置proxy_pass(超简单公式记忆法)

简介: nginx配置proxy_pass(超简单公式记忆法)

问题背景


假如要将8080端口上的请求转发至3000端口。


以3000端口为例,编写proxy_pass有两种形式。


无斜杆:http://localhost:3000

有斜杆:http://localhost:3000/


假设前端请求为http://localhost:8080/get/test


我们暂且把/get/test称为请求部分


无斜杆


proxy_pass:http://localhost:3000。


无斜杆location匹配到的部分也属于请求的部分。


location无论用/get还是用/get/只要匹配上之后都会将整个请求部分/get/test加到proxy_pass上。


http://localhost:3000+/get/test等于请求http://localhost:3000/get/test。


有斜杆


proxy_pass:http://localhost:3000/。


有斜杆location匹配到的部分只用于匹配,不属于请求部分,需要在请求部分将location匹配到的部分剔除。


location用/get则是http://localhost:3000/+(/get/test -/get)等于请求http://localhost:3000//test


location用/get/则是http://localhost:3000/+(/get/test -/get/)等于请求http://localhost:3000/test


斜杠后还有字符串


proxy_pass:http://localhost:3000/abc。


同有斜杆的规则,在请求部分剔除location后加在上面即可。


举个小例


location用/get则是http://localhost:3000/abc+(/get/test -/get)等于请求http://localhost:3000/abc/test


相关文章
|
24天前
|
运维 前端开发 应用服务中间件
LNMP详解(八)——Nginx动静分离实战配置
LNMP详解(八)——Nginx动静分离实战配置
27 0
|
1月前
|
应用服务中间件 nginx
Nginx中如何配置中文域名?
Nginx中如何配置中文域名?
43 0
|
23天前
|
前端开发 应用服务中间件 nginx
Nginx配置详解Docker部署Nginx使用Nginx部署vue前端项目
Nginx配置详解Docker部署Nginx使用Nginx部署vue前端项目
91 0
|
1月前
|
PHP
百度虚拟机 bcloud_nginx_user.conf配置
百度虚拟机 bcloud_nginx_user.conf配置
22 0
|
3天前
|
安全 应用服务中间件 网络安全
SSL原理、生成SSL密钥对、Nginx配置SSL
现在,你的Nginx虚拟主机应该已经配置了SSL,可以通过HTTPS安全访问。确保在生产环境中使用有效的SSL证书来保护通信的安全性。
12 0
|
5天前
|
域名解析 缓存 负载均衡
Nginx正向代理域名的配置
Nginx正向代理域名的配置
|
6天前
|
前端开发 JavaScript 应用服务中间件
修改Jeecg-boot context-path(附加图片+Nginx配置)
修改Jeecg-boot context-path(附加图片+Nginx配置)
12 0
|
16天前
|
应用服务中间件 nginx
nginx进行反向代理的配置
在Nginx中设置反向代理的步骤:编辑`/etc/nginx/nginx.conf`,在http段加入配置,创建一个监听80端口、服务器名为example.com的虚拟主机。通过`location /`将请求代理到本地3000端口,并设置代理头。保存配置后,使用`sudo nginx -s reload`重载服务。完成配置,通过example.com访问代理服务器。
24 0
|
17天前
|
应用服务中间件 网络安全 nginx
nginx配置https访问
nginx配置https访问
28 0
|
26天前
|
应用服务中间件 nginx
nginx配置访问qicaitun.com强制跳转www.qicaitun.com
nginx配置访问qicaitun.com强制跳转www.qicaitun.com
9 0