我有一个 nginx 服务器,并在 /var/www/main-site 中添加一个 laravel 项目,地址为 site.com 我在/var/www/blog 中添加了一个wordpress 项目。我想用此地址显示博客 site.com/blog。 这是我的 nginx 配置
listen 80;
server_name site.com www.site.com;
root /var/www/main-site/public;
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
error_log /var/log/nginx/error.log;
charset utf-8;
location /blog {
alias /var/www/blog;
try_files $uri $uri/ /index.php?$query_string;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
当我致电 site.com 时,它可以工作并显示 laravel 项目。但是当我调用 site.com/blog 时,我看到“找不到文件”,状态为 404。并在 nginx 日志中显示此错误
2024/04/30 22:12:16 [error] 3577550#3577550: *7 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: xxx.xxx.xx.xx, server: site.com, request: "GET /blog/ HTTP/1.1", upstream: "fastcgi://unix:/var/run/php/php8.0-fpm.sock:", host: "site.com"