我正在一个液滴(数字海洋)中安装一个网站。我在使用 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 :/
http://5.101.99.123/info.php
http://5.101.99.123
任何想法?
-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
/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管
server_name
# Make site accessible (...)
server_name localhost;
添加index.php到index行
index.php
index
root /usr/share/nginx/www;
index index.php index.html index.htm;
取消注释location ~ \.php$ {}
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
/etc/php5/fpm/php.ini
cgi.fix_pathinfo
0
重启nginx和php5-fpmsudo service nginx restart && sudo service php5-fpm restart
sudo service nginx restart && sudo service php5-fpm restart
我一周前刚开始使用 Linux,所以我真的希望能在这方面对你有所帮助。我正在使用 nano 文本编辑器来编辑文件。如果没有,请运行 apt-get install nano。谷歌上它以了解更多信息。