【问题标题】:PHP not running on nginx with Debian 8PHP没有在使用Debian 8的nginx上运行
【发布时间】:2018-05-29 17:37:25
【问题描述】:

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

起作用的是PHP。还有一个简单的info.php 文件,其中包含

<?php
  phpinfo();
?>

不工作。

在浏览器客户端我的错误信息是:

404 未找到 nginx/1.6.2

Nginx 的错误日志显示如下:

2018/05/29 19:22:57 [error] 1879#0: *1592 open() "/usr/share/nginx/html/info.php" 失败(2:没有这样的文件或目录),客户端:ip_address,服务器:,请求:“GET /info.php HTTP/1.1”,主机:“

我的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 指南中的所有步骤。但它仍然无法正常工作。那么如何解决呢?

【问题讨论】:

  • 我当然做了
  • 你在更改 nginx 配置和 php-fpm 后是否重启了 web 服务器?确保你应该给/var/run/php5-fpm.sock 777权限
  • 我也试过了:同样的问题

标签: php nginx debian


【解决方案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;
    }
}

【讨论】:

  • 感谢您的回答,我看到 PHP 5 正在运行,:)
【解决方案2】:

这是我正在使用的:

    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;
    }

【讨论】:

  • 应用它对我没有任何改变。我不明白为什么没有为这种典型用例找到任何解决方案?
  • @unlimited101 你把它放在正确的server { ... } 块中了吗?您可以粘贴当前/更改的配置吗?
  • 当然我把它放在上面的块中并删除了这个块:location ~ /.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php5-fpm.sock; }
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-06-01
  • 2019-09-15
  • 1970-01-01
  • 2018-01-07
  • 2023-03-05
  • 1970-01-01
  • 2020-03-11
相关资源
最近更新 更多