環境:centos7 nginx1.16.1
(1)先將tp源代碼下載到nginx的站點目錄下
注意:存放tp的目錄要有可執行權限,否則無法進入目錄,訪問報403
(2)servr配置:
server {
listen 80;
server_name www.fanshehu.xyz localhost;
charset utf8;
access_log logs/host.access.log;
root www/tp5/public;
index index.php index.html index.htm; #如果請求是站點根目錄,則顯示這些頁面
location / { #根目錄,所有請求都能匹配到
if (!-e $request_filename) { #如果請求的不是一個文件或目錄,則重寫。否則請求是站點根目錄或靜態資源,nginx將靜態資源以二進制流返回
rewrite ^/(.*)$ /index.php/$1 last;
break;
}
}
location ~ \.php { #如果請求有.php
root www/tp5/public;
fastcgi_pass 127.0.0.1:9000; #交給php-fpm處理
#fastcgi_index index.php; #如果請求是網站根目錄,則加上index.php在url后,此時$fastcgi_script_name等於index.php。在這里並不需要,可注釋掉
include fastcgi.conf; #引入fastcgi.conf,里面有php-fpm需要的參數
set $real_script_name $fastcgi_script_name; #
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
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;
}
}