虚拟主机:
server {
listen *:8080;
location / {
root /var/www/default/pub;
index index.php;
# if file exists return it right away
if (-f $request_filename) {
break;
}
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php$1 last;
break;
}
}
# serve static files directly
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}
location ~* \.php$ {
# By all means use a different server for the fcgi processes if you need to
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /usr/local/nginx/conf/fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
答案1
您的虚拟主机运行良好(但端口 8080):
# curl localhost:8080/public_/html/index.php
123
/var/www/default/pub/public_/html/index.php:
<?php
echo "123";
?>
答案2
将 php 文件发送到 fpm 的位置块位于服务器块之外(由于多余的 '}' )....所以,当然,nginx 不会将文件传递给 php-fpm,而是按原样提供它,这基本上就是您所描述的症状。
也就是说,您的配置也存在一些其他问题,但与当前的问题无关......
}
location ~* \.php$ {
删除“location”上方的多余的“}”,看看是否能解决问题。