nginx配置proxy_pass URL末尾加与不加/(斜线)的区别

news/2024/7/5 2:57:38

说明

  • curl在终端进行访问,可以避免浏览器缓存影响测试结果
  • 测试结果在本地通过一个虚拟主机8087的acces_log获取
  • 每一条curl下面为对应的测试结果

测试

1

location /tobaidu {
    proxy_pass http://127.0.0.1:8087;
}

curl http://127.0.0.1/tobaidu

http://127.0.0.1:8087/tobaidu

curl http://127.0.0.1/tobaidu/

http://127.0.0.1:8087/tobaidu/

curl http://127.0.0.1/tobaidu/xxxx

http://127.0.0.1:8087/tobaidu/xxxx

2

location /tobaidu {
    proxy_pass http://127.0.0.1:8087/define;
}

curl http://127.0.0.1/tobaidu

http://127.0.0.1:8087/define

curl http://127.0.0.1/tobaidu/

http://127.0.0.1:8087/define/

curl http://127.0.0.1/tobaidu/xxxx

http://127.0.0.1:8087/define/xxxx

3

location /tobaidu/ {
    proxy_pass http://127.0.0.1:8087;
}

curl http://127.0.0.1/tobaidu

重定向到http://127.0.0.1/tobaidu/

curl http://127.0.0.1/tobaidu/

http://127.0.0.1:8087/tobaidu/

curl http://127.0.0.1/tobaidu/xxxx

http://127.0.0.1:8087/tobaidu/xxxx

4

location /tobaidu/ {
    proxy_pass http://127.0.0.1:8087/define;
}

curl http://127.0.0.1/tobaidu

重定向到http://127.0.0.1/tobaidu/

curl http://127.0.0.1/tobaidu/

http://127.0.0.1:8087/define

curl http://127.0.0.1/tobaidu/xxxx

http://127.0.0.1:8087/definexxxx

5

location /tobaidu {
    proxy_pass http://127.0.0.1:8087/;
}

curl http://127.0.0.1/tobaidu

http://127.0.0.1:8087/

curl http://127.0.0.1/tobaidu/

http://127.0.0.1:8087//

curl http://127.0.0.1/tobaidu/xxxx

http://127.0.0.1:8087//xxxx

6

location /tobaidu {
    proxy_pass http://127.0.0.1:8087/define/;
}

curl http://127.0.0.1/tobaidu

http://127.0.0.1:8087/define/

curl http://127.0.0.1/tobaidu/

http://127.0.0.1:8087/define//

curl http://127.0.0.1/tobaidu/xxxx

http://127.0.0.1:8087/define//xxxx

7

location /tobaidu/ {
    proxy_pass http://127.0.0.1:8087/;
}

curl http://127.0.0.1/tobaidu

重定向到http://127.0.0.1/tobaidu/

curl http://127.0.0.1/tobaidu/

http://127.0.0.1:8087/

curl http://127.0.0.1/tobaidu/xxxx

http://127.0.0.1:8087/xxxx

8

location /tobaidu/ {
    proxy_pass http://127.0.0.1:8087/define/;
}

curl http://127.0.0.1/tobaidu

重定向到http://127.0.0.1/tobaidu/

curl http://127.0.0.1/tobaidu/

http://127.0.0.1:8087/define/

curl http://127.0.0.1/tobaidu/xxxx

http://127.0.0.1:8087/define/xxxx

结论

  1. URL符合 protocol://ip:port 同时结尾不加/,则nginx会代理匹配路径部分,否则不代理匹配路径,同时自动添加不匹配路径”部分”,比如/tobaidu/xxxx/xxxx部分

  2. 测试7为常用的反向代理


http://www.niftyadmin.cn/n/2225479.html

相关文章

HDU(3790),最短路二级标准

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid3790 最短路径问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 22854 Accepted Submission(s): 6813 Problem Description给你n个点&#…

通过frm和ibd恢复数据库

文章目录参考地址步骤通过mysqlfrm可以从frm中获取表结构使用批量导出问题新建空的数据库, 导入上述表结构删除对应的表空间, 将表对应的ibd文件复制到数据目录下单个批量重新插入表空间mysql参考地址 https://www.nullalo.com/en/recover-mysql-innodb-tables-without-ibdata…

过滤器 自定义查询

{{ item.date|date:Y-m-d H:i:s }}这种筛选器的效果是打印出 年 月 日 小时 分钟 秒 <p><span class"tutime font-size-18"><a href{% url archive %}?year{{ archive | slice:":4" }}&month{{ archive | slice:"5:7" }}>…

LNMP 一键安装脚本阅读

文章目录基础笔记软件介绍版本号.user.ininginxphp.ini文件描述符系统级别用户级别安装编译安装Mysql后续处理编译安装 php工具编译安装 nginxlua 配置流程安装流程其他工具tool/*addons.sh卸载流程常用命令phpnginxmysqlyumpythoniptables规则服务lnmp 脚本其他源码地址SHELL学…

云服务器安全管理

文章目录说明操作流程用户管理/etc/ssh/sshd_config配置说明操作参考说明 文档主要针对除阿里云和腾讯云外的云服务器所有操作流程都不会影响当前已登录的 ssh 连接, 所以为避免修改配置后无法连接, 在未结束前, 不要断开此次连接 操作流程 删除系统默认创建用户, 如联通云会…

oracle10g RAC Default gateway is not defined (host=rac2) (vm)

http://www.itpub.net/thread-1775304-1-1.html[more] 来自 “ ITPUB博客 ” &#xff0c;链接&#xff1a;http://blog.itpub.net/24237320/viewspace-1060333/&#xff0c;如需转载&#xff0c;请注明出处&#xff0c;否则将追究法律责任。 转载于:http://blog.itpub.net/24…

linux之例行性工作排程:crontab学习

crontab - maintain crontab files for individual users —-是用来让使用者在固定时间或固定间隔执行程序之用 crontab [-u username] [-l|-e|-r] 选项与参数&#xff1a; -u &#xff1a;只有 root 才能进行这个任务&#xff0c;亦即帮其他使用者建立/移除 crontab 工作排…

xxx is not in the sudoers file. This incident will be reported.

sudo是linux系统管理指令&#xff0c;是允许系统管理员让普通用户执行一些或者全部的root命令的一个工具&#xff0c;如halt&#xff0c;reboot&#xff0c;su等等 1.切换到root用户下 2.添加sudo文件的写权限,命令是: chmod uw /etc/sudoers 3.编辑sudoers文件 vi /etc/s…