Nginx将.php文件作为下载文件,而不是执行它们
我正在将站点安装在Droplet中(数字海洋)。我在使用PHP正确安装NGINX时遇到问题,但是当我尝试运行一些.php文件正在下载…例如,http://5.101.99.123/info.php
它正在工作,但是…如果我进入主目录,http://5.101.99.123
它将下载我的index.php:/
任何的想法?
-rw-r--r-- 1 agitar_user www-data 418 Jul 31 18:27 index.php-rw-r--r-- 1 agitar_user www-data 21 Aug 31 11:20 info.php
我的/ etc / nginx / sites-available / default
server { listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/html;
index index.html index.htm index.php;
# Make site accessible from http://localhost/
server_name agitarycompartir.com;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
# # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location / {
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
…评论其他“位置”(#)
回答:
尝试这个:
编辑
/etc/nginx/sites-available/default
取消注释两个侦听行,以使nginx在端口80 IPv4和IPv6上侦听。
listen 80; ## listen for ipv4; this line is default and implied
listen [::]:80 default_server ipv6only=on; ## listen for ipv6
离开
server_name
独自# Make site accessible (...)
server_name localhost;
添加
index.php
到index
行root /usr/share/nginx/www;
index index.php index.html index.htm;
取消评论
location ~ \.php$ {}
```
pass the PHP scripts to FastCGI server listening on (…)
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
# NOTE: You should have “cgi.fix_pathinfo = 0;” in php.ini
# With php5-cgi alone: #fastcgi_pass 127.0.0.1:9000;
# With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
```
编辑
/etc/php5/fpm/php.ini
并确保cgi.fix_pathinfo
设置为0
重新启动Nginx和php5-fpm
sudo service nginx restart && sudo service php5-fpm restart
我一周前才刚刚开始使用Linux,因此我真的希望能在此方面为您提供帮助。我正在使用nano文本编辑器来编辑文件。如果没有,请运行apt-getinstall nano。Google对它了解更多。
以上是 Nginx将.php文件作为下载文件,而不是执行它们 的全部内容, 来源链接: utcz.com/qa/425727.html