我正在安装一个网站在一个液滴(数字海洋)。我有一个问题安装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
            }

...

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

.


当前回答

我在Ubuntu 16.04和php7中使用的是删除这一行

fastcgi_split_path_info ^(. + \。php)美元(/ +);

之后它就停止下载php文件了。

其他回答

我在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) 我的应用文件

vi / etc / nginx / sites-available / myApp

server {
  listen 80;
  listen [::]:80;

  root /var/www/myApp;
  index index.php index.html index.htm;

  location ~ \.php$ {
      try_files $uri =404;
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass unix:/run/php/php7.0-fpm.sock;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
          include fastcgi_params;
      }
}

PHP5用户

改变

fastcgi_pass unix:/run/php/php7.0-fpm.sock;

to

fastcgi_pass unix:/var/run/php5-fpm.sock;

2)配置cgi.fix_pathinfo

cgi。Fix_pathinfo为0

地点:

菲律宾比索5 /etc/php5/fpm/php.ini

PHP7 /etc/php/7.0/fpm/php.ini


3)重启服务

FPM

Php5 sudo service Php5 -fpm restart

Php7 sudo服务php7.0-fpm重启

sudo service nginx restart

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

步骤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

试试这个:

Edit /etc/nginx/sites-available/default Uncomment both listen lines to make Nginx listen on port 80 IPv4 and IPv6. listen 80; ## listen for ipv4; this line is default and implied listen [::]:80 default_server ipv6only=on; ## listen for ipv6 Leave server_name alone # Make site accessible (...) server_name localhost; Add index.php to the index line root /usr/share/nginx/www; index index.php index.html index.htm; 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; } 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,所以我真的希望能帮助到你。我正在使用一个纳米文本编辑器来编辑文件。如果没有,运行apt-get install nano。谷歌想知道更多。

在我的情况下,我没有使用/etc/nginx/sites-available/default,我使用了一个不同的服务器块配置文件(例如example.com),我能够解决这个问题的唯一方法是删除默认的服务器块配置文件符号链接:

$ rm /etc/nginx/sites-enabled/default

然后重新加载Nginx:

$ sudo systemctl reload nginx