我的 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
块中。