nginx url自动加斜杠问题

一、首先对比说明Nginx以下两个现象:

1. 访问的uri最后带斜杠

  http://localhost/product/    >>>>  查找 product下的index页面,存在就返回;不存在且未开启自动索引目录选项(指令是:autoindex on),则报403错误

2. 访问的uri最后不带斜杠

  http://localhost/product     >>>>  查找product文件,存在就返回;若存在product的文件夹,会产生301跳转,且自动将uri补全为http://localhost/product/ ,跳转的域名由server_name_in_redirect 指令控制(下文介绍)

二、server_name_in_redirect 指令配置

1、server_name_in_redirect on ,URL 重定向为: server_name 中的第一个域名 + 目录名 + /;例如 配置文件中 server_name  www.baidu.com;  则http://localhost/product   时会重定向到http://www.baidu.com/product/(这是个坑)
2、server_name_in_redirect off (默认值)URL 重定向为: 原 URL 中的域名 + 目录名 + /。

 

posted @ 2019-08-08 12:01  陈一风  阅读(6123)  评论(0编辑  收藏  举报