php - 安装ssl证书后Nginx不运行php

标签 php ssl nginx

我刚刚为一个新站点设置了 ubuntu 18.04 服务器。 问题是 php 在通过 certbot 安装 ssl 证书后停止工作。

这是位于/etc/nginx/sites-available 的 example.com 配置文件:

server {

        root /var/www/example.com/html;
        index index.html index.htm index.php index.nginx-debian.html;

        server_name example.com www.example.com;

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

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = example.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


        listen 80;
        listen [::]:80;

        server_name example.com www.example.com;
        return 404; # managed by Certbot


}

现在https://example.com返回 application/octet-stream 而不是运行 index.php

我检查过防火墙是否允许连接: lsof -i :443

nginx   30662     root   13u  IPv6  26978      0t0  TCP *:https (LISTEN)
nginx   30662     root   14u  IPv4  26979      0t0  TCP *:https (LISTEN)
nginx   30665 www-data   13u  IPv6  26978      0t0  TCP *:https (LISTEN)
nginx   30665 www-data   14u  IPv4  26979      0t0  TCP *:https (LISTEN)

系统:

Ubuntu 18.04.3 LTS x86_64
nginx version: nginx/1.14.0
PHP Version 7.0.33-0ubuntu0.16.04.7
firewall: ufw 0.36

最佳答案

您必须将此指令添加到您的配置 nginx 中:

location ~* \.php$ {
    #you have to put the path your php-fpm socket file
    fastcgi_pass unix:/path_to_your_socket_file/php7.3-fpm.sock;
    include         fastcgi_params;
    fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;
}

然后你必须重新启动你的 nginx 服务。

来源: https://www.linode.com/docs/web-servers/nginx/serve-php-php-fpm-and-nginx/

如果有什么不对,请告诉我

关于php - 安装ssl证书后Nginx不运行php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59016687/

相关文章:

reactjs - 如何从 nginx 发送请求并将容器 react 到 Spring Boot 容器?

php - 在 PHP 中实例化类实例的不同方法

javascript - 当服务器端脚本可以轻松做到这一点时,为什么浏览器不允许 CORS?

redirect - Haproxy ssl 重定向握手失败

nginx - 如果条件破坏了 nginx 配置中的 try_files

javascript - 使用 nginx+pushstream 模块进行长轮询是否可能会丢失消息?

php - 为多行插入第二个自动递增 id

php - 简单 XML - 处理节点中的冒号

authentication - 安全通信基础知识

mysql - docker下带有外部数据库的Apache Guacamole需要SSL数据库连接