牛骨文教育服务平台(让学习变的简单)
博文笔记

ThinkPHP 3.2 在 Nginx 下配置 URL 模式为 REWRITE 模式

创建时间:2016-02-23 投稿人: 浏览次数:926

在apache下仅需要开启重写,并在网站根目录添加重写配置文件即可。
在nginx中,原理类似,需要对根路径的访问按条件进行URL重写:

server {
        listen 80;
        server_name www.mysite.com;
        root /var/www/www.mysite.com;
        index index.html index.php;
        location / {
                if (!-e $request_filename) {
                        rewrite  ^(.*)$  /index.php?s=$1  last;
                        break;
                }
        }
        location ~ .php {
                fastcgi_split_path_info ^(.+.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}  

第一个 location 节点用于判断当前访问的HTTP资源是否是文件,如不是文件则进行URL重写。

第二个 location 节点用于处理URL中包含 .php 字样的请求,内部通过unix socket的文件IO方式实现网络请求IO,PHP 处理器为 php5-fpm

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。