我创建了一个虚拟专用服务器使用 Nginx 并且我尝试使用以下命令显示 php 信息:<?php phpinfo(); ?>
。
相反,浏览器要求我下载 php 文件,但该文件也没有被解析。
这只发生在我位于的 VPS 网站上/var/www/
。位于默认位置的相同 php 文件/usr/share/nginx/html
(通过 ip 由浏览器访问)显示正常(并显示在浏览器中而不是要求下载)。
这是我的配置文件:
虚拟配置文件
#
# A virtual host using mix of IP-, name-, and port-based configuration
#
server {
listen 80;
# listen *:80;
server_name website.com www.website.com;
location / {
root /var/www/website.com/public_html/;
index index.php index.html index.htm;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/website.com/public_html/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
默认配置文件
#
# The default server
#
server {
listen 80;
server_name 100.00.000.000;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
error_page 404 /404.html;
location = /404.html {
root /usr/share/nginx/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
感谢大家!