使用情景如下:

在访问 http://php.cc/Att/AttList 的时候、跳转到 http://php.cc/index.php/Att/AttList ;

也就是开启重写功能;

在nginx配置文件nginx.conf中添加:

location / {

  if ( !e $request_filename ) {

    rewrite ^/(.*)$ /index.php/$1 last;

  }

}

如果项目入口文件是在一个子目录里面,则如下:

location / {

  if ( !e $request_filename ) {

    rewrite ^/目录/(.*)$ /目录/index.php/$1 last;

  }

}

切记:不可以出现两个location / {}、否则nginx服务器将启动不了;

我的配置文件如下:

server {
  listen 80;
  server_name www.abcphp.cc abcphp.cc;
  root "D:/abc/php";
  location / {
    if (!-e $request_filename) {
      rewrite ^/(.*)$ /index.php?$1 last;
    }
    index index.html index.htm index.php;
    autoindex on;
  }
  location ~ \.php(.*)$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    include fastcgi_params;
  }
}

其中:

autoindex on;  是打开nginx的浏览目录的功能;

原文地址:https://mp.weixin.qq.com/s/ltd3LlZn4vpq1vxCRqSaQQ

nginx 隐藏 index.php的更多相关文章

  1. Nginx隐藏index.php和配置vhost

    nginx启动命令 启动:nginx停止:nginx -s stop退出:nginx -s quit重启:nginx -s reopen重新加载:nginx -s reload平滑启动:kill -H ...

  2. nginx 隐藏 index.php 和 开启 pathinfo 模式的配置

    nginx 通过 location 的规则匹配将 php 转发给 php-fpm 处理后获取结果然后返回给客户端,转发模式可以通过 unix sock 或 tcp socket 方式.百度了好多文章我 ...

  3. nginx 隐藏index.php 并开启rewrite日志调试(apache也有)

    开启rewrite 日志 error_log       /data/log/nginx/error.log notice; 位于最外层,大约在文件的前几行 再在http{}括号里增加一行:rewri ...

  4. TP5框架 nginx服务器 配置域名 隐藏index.php

    server { listen ; #server_name localhost; server_name hhy.com;/**这里写自己的域名*/ #charset koi8-r; #access ...

  5. lnmp 一键安装包 nginx配置tp5 phpinfo模式 隐藏index.php

    tp5 url 线上访问 在nginx 上 出现404错误 那是因为pathinfo没有被支持 修改如下:找到   /usr/local/nginx/config/vhost/项目名.config s ...

  6. nginx服务器绑定多个域名、支持pathinfo路由、隐藏index.php入口文件

    这篇文章仅仅是操作,解释说明部分待更新. 1. 修改nginx的配置文件(我的配置文件在/etc/nginx/nginx.conf) [root@xxx ~]# find / -name nginx. ...

  7. nginx配置隐藏index.php

    Nginx 服务器隐藏 index.php 配置   location / { try_files $uri $uri/ /index.php?$query_string; }   nginx配置中t ...

  8. nginx 环境 thinkphp 隐藏index.php

    tp官网已经写了 http://doc.thinkphp.cn/manual/hidden_index.html 不生效 重启nginx .问题依旧 kill掉nginx进程  再启动 贴段自己的配置 ...

  9. Nginx配置PATHINFO隐藏index.php

    1.网络来源:http://www.shouce.ren/post/view/id/1529 server {      listen       80;     default_type text/ ...

随机推荐

  1. Android Hook框架adbi源码浅析(一)

    adbi(The Android Dynamic Binary Instrumentation Toolkit)是一个Android平台通用hook框架,基于动态库注入与inline hook技术实现 ...

  2. templates的语法

    1.变量 1.作用:将后端的数据传递到模板进行显示 2.允许作为变量的数据类型 字符串,整数,列表,元组,字典,函数,对象 3.变量的语法 变量传递给前端必须要封装到字典中才能传递给模板 1.使用 l ...

  3. 动态规划-----hdu 1024 (区间连续和)

    给定一个长度为n的区间:求m段连续子区间的和 最大值(其中m段子区间互不相交) 思路: dp[i][j]: 前j个元素i个连续区间最大值 (重要 a[j]必须在最后一个区间内) 转移方程:dp[i][ ...

  4. JAVA:形参与实参

    今天百度startWith函数的用法,无意中看到了形参这个称呼,因此就去了解了下形参与实参. 在传值机制中,其实就是把变量b(实参)的地址传递给了形参(也就是实参跟形参都是用的同一个地址,在传值之前形 ...

  5. MyBatis 遍历数组放入in中

    必须要遍历出数组的值放入in中 如果直接将"'2','3','4','5','6','7','8'" 字符串放入in中,只会查出 inv_operate_type的值为2的数据,因 ...

  6. windows 10 下sublime text 3配置c/c++编译环境

    来源于在网上各种帖子,自己成功配置之后写作笔记: 检查环境变量 首先配置重定义环境变量,过程如下: 创建一个test.c文件 内容: #include <stdio.h> int main ...

  7. java-this和super的区别

    1.this和super都代表什么: - this:代表当前对象的引用,谁来调用我,我就代表谁 - super:代表当前对象父类的引用 - super(...)或者this(...)必须放在构造方法的 ...

  8. linux入门001--帮助支持

    linux入门001--帮助支持====1. 帮助手册提供命令的使用说明:man ls提供基础知识和参考信息,有时会有实例和交叉索引,但是基本没有教程式的文档.就是说,并不会有偏重告诉你那个重要,那个 ...

  9. [Wannafly挑战赛28][B msc和mcc][预处理+枚举]

    链接:https://ac.nowcoder.com/acm/contest/217/B来源:牛客网 msc和mcc 题目描述 msc和mcc是一对好朋友,有一天他们得到了一个长度为n的字符串s. 这 ...

  10. 《DSP using MATLAB》Problem5.23

    代码: %% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% O ...