我刚刚为一个新站点设置了 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/