问题描述
我正在将站点安装在Droplet中(数字海洋).我在使用PHP正确安装NGINX时遇到问题.我做了一个教程 https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04 ,但是当我尝试运行一些.php文件,它只是下载中...例如... http://5.101.99.123/info.php
它正在工作,但是...如果我进入主要的http://5.101.99.123
它正在下载我的index.php:/
I am installing a website in a droplet (Digital Ocean). I have a issue for install NGINX with PHP properly. I did a tutorial https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-14-04 but when I try to run some .php file it's just downloading it...for example... http://5.101.99.123/info.php
it's working but... If I go to the main http://5.101.99.123
it's downloading my 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
My /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
}
...其他位置"已被注释(#)
...Others "location" are commented (#)
推荐答案
尝试一下:
-
编辑
/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
Leave server_name
alone
# Make site accessible (...)
server_name localhost;
将index.php
添加到index
行
Add index.php
to the index
line
root /usr/share/nginx/www;
index index.php index.html index.htm;
取消注释location ~ \.php$ {}
Uncomment 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
Edit /etc/php5/fpm/php.ini
and make sure cgi.fix_pathinfo
is set to 0
Restart nginx and php5-fpm sudo service nginx restart && sudo service php5-fpm restart
我一周前才刚刚开始使用Linux,所以我真的希望能在此方面为您提供帮助.我正在使用nano文本编辑器来编辑文件.如果没有,请运行apt-get install nano.谷歌在它上了解更多.
I have just started using Linux a week ago, so I really hope to help you on this. I am using nano text editor to edit the files. run apt-get install nano if you don't have it. Google on it to know more.
这篇关于Nginx将.php文件作为下载文件,而不是执行它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!