用于多个HTTPS(certbot)域的一个nginx配置

问题描述 投票:2回答:1

现在,我在多个域中使用一个Nginx配置。

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

        root /home/user/default;
        index index.php;
        server_name _;
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        }
}

我想将站点转移到https协议,将使用CertBot。

是否还可以对所有域使用一个配置?如何指定不同域的密钥路径?

nginx certbot
1个回答
0
投票

Nginx不能为SSL证书文件路径使用用户变量名,因此对于每个指定文件的主机,您将需要server块。您可以使用include

模块化配置
server {
  include conf.d/includes/common.conf;

  host example1.com www.example1.com;  

  ssl_certificate         /etc/nginx/ssl/example1.com/cert.cer;
  ssl_certificate_key     /etc/nginx/ssl/example1.com/privkey.cer;
  ssl_trusted_certificate /etc/nginx/ssl/example1.com/ca.cer;
}

common.conf

listen 443 ssl http2;
listen [::]:443 ssl http2;

root /home/user/$host;
access_log /var/log/nginx/$host-access.log;
error_log  /var/log/nginx/$host-error.log;

ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4;

index index.php;

location / {
  try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
  include snippets/fastcgi-php.conf;
  fastcgi_pass unix:/run/php/php7.2-fpm.sock;
}

[另一个想法是对一个域使用通配符证书,或者潜在地使用为多个域提供服务的Certbot证书,每次添加新域时都要对其进行更新(请不要尝试,并且Certbot可能有限制或完全禁止多个域)

© www.soinside.com 2019 - 2024. All rights reserved.