I have multiple ssl sites on one server with nginx, and the virtual hosting works like this:

root /var/www/html/$host;

But in the certificate section, the $host variable doesn't work:

ssl_certificate /etc/nginx/ssl/$host.crt;
ssl_certificate_key /etc/nginx/ssl/$host.key;

How can I solve this?

  • Just use different config files. If you insist on using just one, Use a symbolic link. – David Betz Feb 16 '16 at 21:11

I doubt ssl_certificate can be parametrized - it's parsed when nginx is started, so the process must know it's filename to perform OpenSSL initialization process, but in case of parametrized vhosts this is just not possible - server_name isn't known.

You have to create non-parametrized vhost configuration files for SSL, or use wildcard certificates (for example *.foo.bar) and semi-parametrized vhosts, like server_name *.foo.bar;.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.