nginx 部署thinkphp 做的東西, 配置 Pathinfo 模式,終於配好了


  用thinkphp做了一個網站,部署到ubuntu上的時候需要,服務器用的是nginx,本身不支持pathinfo模式,需要修改配置文件,使其能夠用pathinfo。

  我用的是虛擬主機的方式。之前配置了好久,總是出現各種各樣的問題,最后實在不行,直接用rewrite模式,配置還比較簡單。后來不知道改了什么,rewrite也不能用了,這回打算把

pathinfo 配出來, 所以查了各種資料,一點一點的改。終於改成了。

  發現很多網上的東西,其實和自己用的經常會有一點差別,需要根據自己的東西進行修改才行

server {
        listen   8082;

        root /usr/share/nginx/www/ssdf;
        index index.php index.html index.htm;

        error_page 404 /404.html;                            //404和后面的“/” 需要有一個空格隔開

        # pass the PHP scripts to FastCGI server listening on the php-fpm socket
        location / {                                         //這里是rewrite規則,可以單獨使用,thinkphp中模式也要改成rewrite,
         if (!-e $request_filename) {              //之前配置好了,不知道后來改了那不能用了。
           rewrite  ^/(.*)$  /index.php/$1   last;
           break;
            }
        }

        location ~ ^(.+\.php)(.*) {
#               try_files $uri =404;         這句只是嘗試注釋掉了,后來也沒再嘗試不注釋能不能用
#               fastcgi_pass 127.0.0.1:9000;       這里一開始寫的詞句,后來修改成default文件中的下面那一句,這句不知道這兩句怎么用
                fastcgi_pass unix:/run/php5-fpm.sock;
                fastcgi_index index.php;
#               include fastcgi_params;            這里面fastcgi_params和 fcgi.conf內容是相同的,網上兩種命名都有人用
                include fcgi.conf;

                set $real_script_name $fastcgi_script_name;
                set $path_info "";
                if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$"){     //if語句后面一定要有個空格,要和別的區分開,屬於語法規定
                        set $real_script_name $1;
                        set $path_info $2;
                }
                fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
                fastcgi_param SCRIPT_NAME $real_script_name;
                fastcgi_param   PATH_INFO $path_info;
        }


}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM