搭建TP5項目nginx配置

完整nginx配置:php

server {
        listen       80;
        server_name  shop.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        root   "C:/phpstudy/WWW/o2o_shop/public";
        location / {
            index  index.html index.htm index.php ;
            autoindex  on;
            if (!-e $request_filename) {  
                    rewrite ^(.*)$ /index.php?s=$1 last;  
                    break;  
                }  

        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php(.*){
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^(.+\.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;
        }
         
        
    }

配置實現pathinfo,404錯誤:html

location ~ \.php(.*){
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^(.+\.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;
}

 

403錯誤配置: 這個默認是off的  意思是禁止訪問目錄  須要開啓nginx

autoindex on;

 

經過URL重寫隱藏應用的入口文件 index.phpthinkphp

https://www.kancloud.cn/manual/thinkphp5/177576thinkphp5

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

}
相關文章
相關標籤/搜索