查找并打開nginx配置文件地址
# nginx -t
# vim /usr/local/nginx/conf/nginx.conf
在http的{}里最后一行加入以下內(nèi)容
include /www/vhost/*.conf; //導(dǎo)入www/vhost下所有配置文件
新建一個(gè)配置文件
# vim default.conf
輸入以下內(nèi)容:
server
{
listen 80; #監(jiān)聽的端口
server_name default.bt localhost; #域名
index index.php index.html index.htm default.php default.htm default.html; #默認(rèn)文檔
root /www/wwwroot/default/; #網(wǎng)站的根目錄
#SSL-START SSL相關(guān)配置校镐,請(qǐng)勿刪除或修改下一行帶注釋的404規(guī)則
#error_page 404/404.html;
#SSL-END
#ERROR-PAGE-START 錯(cuò)誤頁配置媚赖,可以注釋头镊、刪除或修改
#error_page 404 /404.html;
#error_page 502 /502.html;
#ERROR-PAGE-END
#PHP-INFO-START PHP引用配置纪他,可以注釋或修改
include /www/vhost/php_version/php74.conf;
#PHP-INFO-END
#REWRITE-START URL重寫規(guī)則引用(單一入口)
include /www/vhost/rewrite/thinkphp.conf;
#REWRITE-END
#禁止訪問的文件或目錄
location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md)
{
return 404;
}
#一鍵申請(qǐng)SSL證書驗(yàn)證目錄相關(guān)設(shè)置
location ~ \.well-known{
allow all;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
error_log /dev/null;
access_log /dev/null;
}
location ~ .*\.(js|css)?$
{
expires 12h;
error_log /dev/null;
access_log /dev/null;
}
access_log /www/wwwlogs/example.bt.log;
error_log /www/wwwlogs/example.bt.error.log;
}
在vhost中新建php_version文件夾 并新建php74.conf文件
# mkdir php_version
# vim php74.conf //中間的74是php的保本號(hào),用于區(qū)分php不通版本的配置文件
在 php74.conf 輸入以下內(nèi)容:
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass 127.0.0.1:7421; #此處默認(rèn)端口號(hào)是9000 因?yàn)橐b多個(gè)版本 所以修改為7421了
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /usr/local/nginx/conf/fastcgi_params; #可用find查找到fastcgi_params填入實(shí)際路徑
}
在vhost中新建rewrite文件夾并且新建 thinkphp.conf 此文件用于單一入口
# mkdir rewrite
# vim thinkphp.conf
加入以下內(nèi)容(think的單一入口配置)
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /admin.php?s=$1 last; break;
}
}