![Nginx vhost 下载文件](https://linux22.com/image/672298/Nginx%20vhost%20%E4%B8%8B%E8%BD%BD%E6%96%87%E4%BB%B6.png)
我已经将 nginx 和 php 设置为本教程建议。我创建了第二个虚拟主机,如下所示:
server {
listen 80;
root /projects/mydomain/;
index index.php index.html index.htm;
server_name mydomain.gr;
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
如果我访问 mydomain.gr/index.php,Php 和 nginx 可以正常工作,但是当我访问 mydomain.gr 时,它会下载一个包含 index.php 内容的文件,名称为 download。我做错了什么?
答案1
使用 try_files 而不是索引:
server {
listen 80;
root /projects/mydomain/;
try_files $uri $uri/index.php $uri/index.html $uri/index.htm =404;
server_name mydomain.gr;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}