溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

如何設(shè)置nginx隱藏index.php

發(fā)布時間:2020-07-27 10:36:18 來源:億速云 閱讀:790 作者:Leah 欄目:編程語言

本篇文章為大家展示了如何設(shè)置nginx隱藏index.php,代碼簡明扼要并且容易理解,絕對能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

nginx隱藏index.php的方法:首先找到并打開“nginx.conf”配置文件;然后添加語句“rewrite ^/(.*)$ /index.php/$1 last;”;最后保存該文件即可。

nginx隱藏index.php的設(shè)置方法

在訪問 http://php.cc/Att/AttList 的時候、跳轉(zhuǎn)到http://php.cc/index.php/Att/AttList ;

也就是開啟重寫功能;

在nginx配置文件nginx.conf中添加:

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

如果項目入口文件是在一個子目錄里面,則如下:

location / {
if ( !e $request_filename ) {
rewrite ^/目錄/(.*)$ /目錄/index.php/$1 last;
}
}

切記:不可以出現(xiàn)兩個location / {}、否則nginx服務(wù)器將啟動不了;

我的配置文件如下:

server {
listen 80;
server_name www.abcphp.cc abcphp.cc;
root "D:/abc/php";
location / {
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?$1 last;
}
index index.html index.htm index.php;
autoindex on;
}
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;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
}

其中:

autoindex on; 是打開nginx的瀏覽目錄的功能;

上述內(nèi)容就是如何設(shè)置nginx隱藏index.php,你們學(xué)到知識或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識儲備,歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI