nginx訪問配置

配置pathinfo模式, 隱藏index.php、配置多站點,更改nginx.conf文件

1、修改nginx.conf配置pathinfo模式、正則匹配.php后面的pathinfo部分

原配置
    location ~ \.php$ {
        root           html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        include        fastcgi_params;
    }
改為
    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;
        include        fastcgi_params;
    }

2、修改nginx.conf隱藏index.php,

添加
    if (!-e $request_filename) {
            rewrite  ^(.*)$  /public/index.php?s=/$1  last;
            break;
        }
到
    location / {
        index  index.html index.htm;
        if (!-e $request_filename) {
            rewrite  ^(.*)$  /public/index.php?s=/$1  last;
            break;
        }
    }
注意:/public/index.php,如果站點項目指向index.php目錄,則去掉/public

3、配置多站點,支持pathinfo模式及隱藏index.php文件

1、打開nginx.conf文件再末尾添加內(nèi)容 引入文件;
    單文件多配置添加:include vhosts.conf;
    多文件單配置添加:include *.conf;
2、打開vhosts.conf站點配置,記住路徑必須是正斜線。
        server {
        listen       80;
        server_name  www.lllanpl.com ;
        root   /usr/local/server/www/lllanpl;
        location / {
            index  index.html index.htm index.php;
            if (!-e $request_filename) {
                rewrite ^/(.*)$ /index.php$1 last;
                break;
            }
        }
        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  $1;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;
            include        fastcgi_params;
        }
    }
 3、修改hosts文件
    添加內(nèi)容:127.0.0.1 www.common.com
    1、linux一般處于/etc/hosts下修改完成重啟服務、網(wǎng)絡即可
        centos7 重啟網(wǎng)絡:service network restart
        centos8 重啟網(wǎng)絡:nmcli c reload
    2、window 系統(tǒng)一般處于C:\Windows\System32\drivers\etc\下修改后重啟服務
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容