upstream <%= name %>-ssl-proxy {
  server localhost:<%= @listen_port %>;
}

server {
  server_name <%= vhost %>  <%= aliases.join(" ") unless aliases.empty? %>;

  listen              443 ssl;
  ssl_certificate     /etc/nginx/ssl/<%= vhost %>.crt;
  ssl_certificate_key /etc/nginx/ssl/<%= vhost %>.key;
  include             /etc/nginx/ssl.conf;

  proxy_set_header Host $http_host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-Server $host;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_redirect off;

  access_log /var/log/nginx/<%= vhost %>-access.log timed_combined;
  error_log /var/log/nginx/<%= vhost %>-error.log;

  location / {
<%- if @internal_only -%>
    # Only accept connnections from internal machines
    allow 10.0.0.0/8;
    allow 127.0.0.1;
    deny all;
<%- end -%>
    proxy_pass https://<%= name %>-ssl-proxy;
  }
}

upstream <%= name %>-ssl-proxy {
  server localhost:<%= @listen_port %>;
}

server {
  server_name <%= vhost %>  <%= aliases.join(" ") unless aliases.empty? %>;

  listen              443 ssl;
  ssl_certificate     /etc/nginx/ssl/<%= vhost %>.crt;
  ssl_certificate_key /etc/nginx/ssl/<%= vhost %>.key;
  include             /etc/nginx/ssl.conf;

  proxy_set_header Host $http_host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-Server $host;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_redirect off;

  access_log /var/log/nginx/<%= vhost %>-access.log timed_combined;
  error_log /var/log/nginx/<%= vhost %>-error.log;

  location / {
<%- if @internal_only -%>
    # Only accept connnections from internal machines
    allow 10.0.0.0/8;
    # Office IP when on CDN02
    allow 80.194.52.34;
    # Office IP when on CDN02_test
    allow 80.194.77.100;
    allow 127.0.0.1;
    deny all;
<%- end -%>
    proxy_pass https://<%= name %>-ssl-proxy;
  }
}

Allow office IP to access app loadbalancers
Allow office IP to access app loadbalancers
