nginx 修改配置文件使之支持pathinfo,且隐藏index.php

声明环境:

nginx
centos6.8
使用lnmp一键包搭建环境(2019年2月19日 )

以前使用过别的办法去修改配置文件,但是过于繁琐,最近发现新版本中,在nginxconf目录下发现了文件“enable-php-pathinfo.conf”,随后发现另外一种及其简单让nginx支持pathinfo的修改办法。
首先找到你的 nginx.conf 文件。
我本人使用的是一键环境,nginx.conf 所在目录为:/usr/local/nginx/conf
如果找不到可以使用命令:find / -name .user.ini
查找
打开文件,找到
配置文件
找到 include enabled-php.conf 更换成 include enable-php-pathinfo.conf;即可

在这里插入图片描述
随后重启服务器:service nginx restart
在这里插入图片描述

已经可以访问,接下来去掉index.php
继续在nginx.conf文件中修改,在其文件中增加:
隐藏index.php的配置

location / {
     	     if (!-e $request_filename) {
     			rewrite  ^(.*)$  /index.php?s=$1  last;
      			break;
    	      }
    	}

随后重启服务器:service nginx restart
解决~

发布了110 篇原创文章 · 获赞 147 · 访问量 17万+

猜你喜欢

转载自blog.csdn.net/A757291228/article/details/88668475