说明:
location 中的 root 和 alias
root 指令只是将搜索的根设置为 root 设定的目录,即不会截断 uri,而是使用原始 uri 跳转该目录下查找文件
aias 指令则会截断匹配的 uri,然后使用 alias 设定的路径加上剩余的 uri 作为子路径进行查找
location 中的 proxy_pass 的 uri
如果 proxy_pass 的 url 不带 uri
如果尾部是"/",则会截断匹配的uri
如果尾部不是"/",则不会截断匹配的uri
如果proxy_pass的url带uri,则会截断匹配的uri
examples
location中的 root
root@pts/1 $ ls -ld /data/web/lctest*|awk '{print $nf}' /data/web/lctest /data/web/lctest2 /data/web/lctest3 /data/web/lctest4 location /lctest { root /data/web/; } location /lctest2/ { root /data/web/; } location /lctest3 { root /data/web; } location /lctest4/ { root /data/web; }
curl 测试结果如下
备注: 浏览器输入的时候最后面不添加 / , 会自动补上,但是curl 不行
root@pts/1 $ curl http://tapi.xxxx.com/lctest/ hello world root@pts/1 $ curl http://tapi.xxxx.com/lctest2/ hello world 2 root@pts/1 $ curl http://tapi.xxxx.com/lctest3/ 3 hello world root@pts/1 $ curl http://tapi.xxxx.com/lctest4/ hello world 4
location alias
location /lctest5 { alias /data/web/; } location /lctest6/ { alias /data/web/; } location /lctest7 { alias /data/web; } ## 403 /data/web forbidden location /lctest8/ { alias /data/web; }
curl 测试结果如下
curl 'http://tapi.kaishustory.com/lctest5/' curl 'http://tapi.kaishustory.com/lctest6/' curl 'http://tapi.kaishustory.com/lctest7/' 结果都是 /data/web/index.html的输出 root@pts/1 $ curl 'http://tapi.kaishustory.com/lctest8/' <html> <head><title>403 forbidden</title></head> <body bgcolor="white"> <center><h1>403 forbidden</h1></center> <hr><center>nginx</center> </body> </html>
location proxy_pass
#--------proxy_pass配置--------------------- location /t1/ { proxy_pass http://servers; } #正常,不截断 location /t2/ { proxy_pass http://servers/; } #正常,截断 location /t3 { proxy_pass http://servers; } #正常,不截断 location /t4 { proxy_pass http://servers/; } #正常,截断 location /t5/ { proxy_pass http://servers/test/; } #正常,截断 location /t6/ { proxy_pass http://servers/test; } #缺"/",截断 location /t7 { proxy_pass http://servers/test/; } #含"//",截断 location /t8 { proxy_pass http://servers/test; } #正常,截断
测试脚本
for i in $(seq 8) do url=http://tapi.xxxx.com/t$i/doc/index.html echo "-----------$url-----------" curl url done
测试结果
----------http://tapi.xxxx.com/t1/doc/index.html------------ /t1/doc/index.html ----------http://tapi.xxxx.com/t2/doc/index.html------------ /doc/index.html ----------http://tapi.xxxx.com/t3/doc/index.html------------ /t3/doc/index.html ----------http://tapi.xxxx.com/t4/doc/index.html------------ /doc/index.html ----------http://tapi.xxxx.com/t5/doc/index.html------------ /test/doc/index.html ----------http://tapi.xxxx.com/t6/doc/index.html------------ /testdoc/index.html ----------http://tapi.xxxx.com/t7/doc/index.html------------ /test//doc/index.html ----------http://tapi.xxxx.com/t8/doc/index.html------------ /test/doc/index.html
以上是nginx location中uri的截取如何实现的详细内容。更多信息请关注PHP中文网其他相关文章!

确认 Nginx 是否启动的方法:1. 使用命令行:systemctl status nginx(Linux/Unix)、netstat -ano | findstr 80(Windows);2. 检查端口 80 是否开放;3. 查看系统日志中 Nginx 启动消息;4. 使用第三方工具,如 Nagios、Zabbix、Icinga。

要关闭 Nginx 服务,请按以下步骤操作:确定安装类型:Red Hat/CentOS(systemctl status nginx)或 Debian/Ubuntu(service nginx status)停止服务:Red Hat/CentOS(systemctl stop nginx)或 Debian/Ubuntu(service nginx stop)禁用自动启动(可选):Red Hat/CentOS(systemctl disable nginx)或 Debian/Ubuntu(syst

如何在 Windows 中配置 Nginx?安装 Nginx 并创建虚拟主机配置。修改主配置文件并包含虚拟主机配置。启动或重新加载 Nginx。测试配置并查看网站。选择性启用 SSL 并配置 SSL 证书。选择性设置防火墙允许 80 和 443 端口流量。

服务器无权访问所请求的资源,导致 nginx 403 错误。解决方法包括:检查文件权限。检查 .htaccess 配置。检查 nginx 配置。配置 SELinux 权限。检查防火墙规则。排除其他原因,如浏览器问题、服务器故障或其他可能的错误。

在 Linux 中启动 Nginx 的步骤:检查 Nginx 是否已安装。使用 systemctl start nginx 启动 Nginx 服务。使用 systemctl enable nginx 启用在系统启动时自动启动 Nginx。使用 systemctl status nginx 验证启动是否成功。在 Web 浏览器中访问 http://localhost 查看默认欢迎页面。

在 Linux 中,使用以下命令检查 Nginx 是否已启动:systemctl status nginx根据命令输出进行判断:如果显示 "Active: active (running)",则 Nginx 已启动。如果显示 "Active: inactive (dead)",则 Nginx 已停止。

问题的答案:304 Not Modified 错误表示浏览器已缓存客户端请求的最新资源版本。解决方案:1. 清除浏览器缓存;2. 禁用浏览器缓存;3. 配置 Nginx 允许客户端缓存;4. 检查文件权限;5. 检查文件哈希;6. 禁用 CDN 或反向代理缓存;7. 重启 Nginx。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

安全考试浏览器
Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境