我正在安装一个网站在一个液滴(数字海洋)。我有一个问题安装NGINX与PHP正确。我做了一个教程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:/

任何想法?

-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

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
            }

...

其他“地点”被评论为……

.


当前回答

还有一件事需要检查:如果你在设置PHP之前设置了HTTPS访问——我使用certbot——你需要在/etc/nginx/sites-available/default中进行两次更改,因为将有两个服务器块(一个在端口80上侦听,一个在端口443上侦听)。

(我设置这个服务器主要是为了电子邮件,当我第一次安装nginx时,我没有任何PHP的用途,只是为了更容易地运行certbot。)

其他回答

你需要把这个添加到/etc/ Nginx /sites-enabled/default中来执行Nginx服务器上的php文件:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;
    
    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.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;
    }
}

我在Mac上用自制软件安装了PHP,在我的情况下,PHP -fpm服务没有运行。

brew services list

启动服务,php脚本开始执行。

brew services start php

我的fastcgi设置在nginx服务器位置块

location ~ \.php$ {
  ...
  include        fastcgi_params;
  fastcgi_pass   127.0.0.1:9000;
  ...
}

如果你提出的任何答案都不管用,试试这个:

1.修复etc/php5/fpm/pool.d中的www.conf:

Listen = 127.0.0.1:9000;(删除所有包含Listen =的行)

2.修复usr/local/nginx/conf中的nginx.conf

删除块html{}中的服务器块server{}(如果存在),因为我们默认使用server{}(配置文件etc/nginx/site-available),它包含在nginx.conf中。

3.修复etc/nginx/site-available中的默认文件

位置~ \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index . php。 包括fastcgi_params; }

4.重新启动nginx服务

Sudo服务nginx重启

5.重启PHP服务

Service php5-fpm restart

6.享受

在/usr/share/nginx/html目录下创建任意php文件,然后运行server_name/file_name.php (server_name取决于你的配置,通常是localhost, file_name.php是在/usr/share/nginx/html中创建的文件名)。

我使用的是Ubuntu 14.04

如果还有什么对你没用的话。也许之前你用info。php测试文件安装了apache2。只需清除本地主机的应用程序数据(缓存,cookie)。

对我来说是这样的: fastcgi_pass unix: / var /运行/ php5-fpm.sock;

这必须是公正的: fastcgi_pass unix: / / php5-fpm.sock运行;