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

在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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章