我正在安装一个网站在一个液滴(数字海洋)。我有一个问题安装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-fpm没有运行,我用服务php7.2-fpm start修复了它。

其他回答

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

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

更新nginx config /etc/nginx/sites-available/default或你的配置文件

如果你正在使用php7,使用这个

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php7.0-fpm.sock;      
    }

如果你正在使用php5,请使用这个

    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
            fastcgi_pass unix:/run/php/php5-fpm.sock;
            fastcgi_index index.php;
            include fastcgi_params;
    }

详情请访问这里

检查你的nginx配置文件扩展名为*.conf。 例如:/etc/nginx/conf.d/myfoo.conf

我也遇到了同样的情况。在我将我的配置文件从myfoo重命名为myfoo.conf后,它修复了。 不要忘记在重命名nginx后重新启动它。

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

我在这个问题上挣扎了很长时间,这些步骤对我很有效。

步骤1:所有PHP文件的位置块配置

location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass unix:/run/php/php7.3-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
}

步骤2:在配置文件中添加fastcgi_param 我们只需要打开/etc/nginx/fastcgi_params文件,并在文件末尾添加以下一行。

fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;

然后重新启动服务,

systemctl restart php7.3-fpm
systemctl restart nginx