Now I use one nginx config for many domains.
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;
}
}
I want to transfer sites to the https protocol, will use the CertBot.
Is it also possible to use one config for all domains? How to specify key paths for different domains?
Nginx can't user variable names for SSL cert file paths, so you'll need server blocks for each host specifying the files. You could modularize your config with 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;
}
Another idea is to use a wildcard cert for a domain, or potentially use a Certbot cert that serves multiple domains, updating it every time a new domain is to be added (never tried and Certbot may have restrictions or disallow multiple domains entirely)