Answer the question
In order to leave comments, you need to log in
Two domains with https on one site on nginx+php-fpm?
Hello.
There is a site with two domains for ru and eng zones. The engine itself parses the content based on the requested domain.
Now I'm transferring the site to nginx + php-fpm, everything works fine through server_name, the speed is great, caching is generally a fairy tale. But, the question arose of how to attach two certificates to this. Everywhere there is infa that only one certificate is registered in the config.
Is it possible to somehow prescribe different certificates in the nginx config depending on the requested domain?
Something like:
server_name rus.ru eng.com;
if $domen = rus.ru {
ssl_certificate "/var/www/httpd-cert/rus.ru.crtca";
ssl_certificate_key "/var/www/httpd-cert/rus.ru.key";
}
if $domen = eng.com {
ssl_certificate "/var/www/httpd-cert/eng.com.crtca";
ssl_certificate_key "/var/www/httpd-cert/eng.com.key";
}
root /var/www/data;
Answer the question
In order to leave comments, you need to log in
server {
listen *:443 ssl;
server_name domain1.com;
ssl_certificate /path/to/domain1.crt;
ssl_certificate_key /path/to/domain1.key;
location / {
proxy_pass http://myapp1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
}
server {
listen *:443 ssl;
server_name domain2.com;
ssl_certificate /path/to/domain2.crt;
ssl_certificate_key /path/to/domain2.key;
location / {
proxy_pass http://myapp1;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
}
}
Is it possible to somehow prescribe different certificates in the nginx config depending on the requested domain?
Since version 1.15.9 you can use variables in the file name when using OpenSSL 1.0.2 and higher:
ssl_certificate $ssl_server_name.crt; ssl_certificate_key $ssl_server_name.key;
In theory, nginx quite supports one certificate per virtual host.
You just need to create several virtual hosts
server {
listen 443;
server_name example.org;
root /usr/share/nginx/www;
index index.html index.htm;
ssl on;
ssl_certificate /etc/nginx/ssl/example.org/server.crt;
ssl_certificate_key /etc/nginx/ssl/example.org/server.key;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question