PHP没有使用Debian 8在nginx上运行

时间:2018-05-29 17:37:25

标签: php nginx debian

我刚用nginx配置了我的Debian 8服务器。我可以浏览html文件。我使用let's encrypt成功运行,也可以自动将http重定向到https。

的工作原理是PHP。还有一个带有

的简单info.php文件
<?php
  phpinfo();
?>

不起作用。

在浏览器客户端上,我的错误消息是:

  

404 Not Found nginx / 1.6.2

的Nginx&#39;错误日志显示:

  

2018/05/29 19:22:57 [错误] 1879#0:* 1592 open()&#34; /usr/share/nginx/html/info.php"失败(2:没有这样的文件或目录),客户端: ip_address ,server :, request:&#34; GET /info.php HTTP / 1.1&#34;,host:&#34; &#34;

我的nginx配置是:

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

    # SSL configuration
    server_name my-server.de www.my-server.de;
    return 301 https://$server_name$request_uri;

    root /var/www/html;

    index index.php index.html index.htm index.nginx-debian.html;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ /.php$ {
        include snippets/fastcgi-php.conf;

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

    location ~ /\.ht {
        deny all;
    }
}

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;

    include snippets/ssl-my-server.de.conf;
    include snippets/ssl-params.conf;
}

即使我将info.php移至/usr/share/nginx/html,客户端浏览器也只会下载info.php文件。

我完成了this指南中的所有步骤。但它仍然无法正常工作。那么如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

你没有在SSL监听端口443中添加,并且加密的ssl配置,请注释301重定向,测试PHP,而不是去配置SSL请参阅https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-debian-8

我看到您添加了SSL配置,需要修复如下nginx配置,重定向后,PHP应在443 not on 80上配置。

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name my-server.de www.my-server.de;
    # Redirect to HTTPS    
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;

    include snippets/ssl-my-server.de.conf;
    include snippets/ssl-params.conf;


    root /var/www/html;

    index index.php index.html index.htm index.nginx-debian.html;

    location / {
        try_files $uri $uri/ =404;
    }

    location ~ /.php$ {
        include snippets/fastcgi-php.conf;

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

    location ~ /\.ht {
        deny all;
    }
}

答案 1 :(得分:0)

这就是我正在使用的:

    upstream php {
            server 127.0.0.1:9000;
            server unix:/var/run/php5-fpm.sock down;
    }


    location ~* \.php$ {
            root /var/www/html/;
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            fastcgi_read_timeout 180;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

            include fastcgi_params;
            fastcgi_pass php;
            fastcgi_index index.php;
    }