我的 Web 根目錄 (/var/www) 中有多個站點,例如 site1、site2 等,我配置 Nginx 如下:
## PHP-FPM Servers ##
upstream localhost-php-fpm {
server unix:/var/run/php/php7.3-fpm.sock;
}
server {
server_name localhost;
listen 80;
root /var/www;
index index.php index.html index.htm;
location /site1/web {
try_files $uri $uri/ /site1/web/index.php?$args;
}
location /site2/web {
try_files $uri $uri/ /site2/web/index.php?$args;
}
# pass to php-fpm
location ~ \.php(?:$|/) {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass localhost-php-fpm;
fastcgi_index index.php;
fastcgi_intercept_errors on;
include fastcgi_params;
fastcgi_connect_timeout 600;
fastcgi_send_timeout 600;
fastcgi_read_timeout 15000;
}
}
例如,當我請求網站的根目錄時http://localhost/site1/web
,會開啟一個下載視窗以下載index.php。但是當我請求某些路徑時,http://localhost/site1/web/dashboard
一切正常。
答案1
您需要將該try_files
指令新增到最後一個location
區塊。