title: Dynamic default.conf of nginx in docker
body: <p>This is my <code>default.conf</code>
  I'm replacing the original <code>default.conf</code> with the following one in my Dockerfile.</p>
  
  <pre><code>server {
      listen                          80;
      server_name                     $servername;
      return 301                      https://$server_name$request_uri;
  }
  
  server {
  
      listen 443;
      server_name $servername;
  
      ssl_certificate           /etc/ssl/private/server.crt;
      ssl_certificate_key       /etc/ssl/private/server.key;
  
      ssl on;
  
      access_log            /var/log/nginx/ghost.access.log;
  
      location / {
  
        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Proto $scheme;
  
        proxy_pass          http://xxx:2368;
        proxy_read_timeout  90;
  
        proxy_redirect      http://xxx:2368 https://$servername:443;
      }
  }
  </code></pre>
  
  <p>The error I receive is </p>
  
  <pre><code>2017/06/26 21:08:15 [emerg] 1#1: unknown "servername" variable
  nginx: [emerg] unknown "servername" variable
  </code></pre>
  
  <p>When I replace <code>$servername</code> with 192.168.xx.xx (the real IP of my server), than everything works fine. But I want it to be dynamic.</p>
  
  <p>How can I define the value of the $servername so that my docker will pick it up and it will be used by nginx?</p>
  
  <p>Or can I write my default.conf in another way to make this dynamic?</p>