我刚刚为新站点设置了ubuntu 18.04服务器。 问题是通过certbot安装ssl证书后php停止工作。
这是example.com配置文件,位于/ etc / nginx / sites-available:
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返回应用程序/八位字节流,而不是运行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
答案 0 :(得分:1)
您必须将此指令添加到您的配置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/
如果有问题请让我
答案 1 :(得分:1)
尝试一下
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 ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_read_timeout 180;
}
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
}