1

I'm trying to set up a default server in nginx with SSL, path to SSL certificate should contain sitename, something like that

server {
    listen 80 default_server;
    listen 443 ssl default_server;
    server_name _;
    ssl_certificate ssl/$http_host/fullchain.pem;
    ssl_certificate_key ssl/$http_host/privkey.pem;

and it doesn't work - in error log cannot load certificate "/etc/nginx/ssl//fullchain.pem" If I print this variable in headers with add_header XX "$http_host"; it shows the proper sitename. Is there any way to use sitename in certificate path? There are a lot of sites on my server with typical config so it's better for me to have just one config. Nginx version 1.18 and if I manually define some variable and put it in ssl_certificate parameter everything is working fine

Belomor
  • 11
  • 2

1 Answers1

1

There is no variable $host_name in nginx. Most likely you want to use $host.

Tero Kilkanen
  • 34,499
  • 3
  • 38
  • 58
  • Thank you - it was a typo. I use $http_host with the same result – Belomor Sep 06 '20 at 14:14
  • 1
    $http_host is extracted from the request headers processed but in your case it is used when nginx is starting and there are no requests yet to process. Use $host as suggested but you'll need to change your server_name. – AlexD Sep 06 '20 at 14:32