title: redirect reverse-proxy to SSL depending on origin of request
body: <p>I have an NGINX server which binds to port 443, provides authentication, and reverse-proxies all SSL requests to a bunch of back-end servers. Another server listens on port 80, but it momentarily does simply leads to a placeholder page. How do I get NGINX to redirect all external requests to the SSL-protected sites, while redirecting all intranet requests to the same sites without SSL? Here is the relevant part of my nginx.conf:</p>
  
  <pre><code>server {
      listen       80;
      server_name  intranet;
  allow 10.10.0.0/16;
      #charset koi8-r;
      access_log  logs/host.access.log  main;
  
  #######################################
  #
  # locations on LOCALHOST
  #
  #######################################         
  
      location / {
      allow   all;
          root   /data/www;
              index  index.html index.htm;
          }
  ##############
  # HTTPS server
  ##############
  
  server {
      listen       443 ssl;
      server_name  localhost;
  
      ssl_certificate      /srv/ssl/ExternalSite.com.combined.crt;
      ssl_certificate_key  /srv/ssl/ExternalSite.key;
  
      ssl_session_cache    shared:SSL:1m;
      ssl_session_timeout  5m;
  
      ssl_ciphers  HIGH:!aNULL:!MD5;
      ssl_prefer_server_ciphers  on;
  
  
      #######################################
      #
      # Reverse proxy blocks
      #
      #######################################         
  
  
      #General ExternalSite web site
      location / {
          auth_basic "Please enter userid and password to enter the ExternalSite web site";
          auth_basic_user_file /var/www/www.ExternalSite.com/.htpasswd;
          proxy_buffers 16 4k;
          proxy_buffer_size 2k;
          proxy_buffering off;   
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header Accept-Encoding "";
          proxy_pass http://10.10.10.16:2080;
          }       
  
      #nagios server 
      location  /nagios  {
          auth_basic "Please enter userid and password to enter the ExternalSite nagios web site";
          auth_basic_user_file /var/www/www.ExternalSite.com/.htpasswd;
          proxy_set_header Authorization $http_authorization;
          proxy_buffers 16 4k;
          proxy_buffer_size 2k;
          proxy_buffering off;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header Accept-Encoding "";
          proxy_pass http://10.10.10.18/nagios;
          }       
  
      # # munin server
      location  /munin  {
          auth_basic "Please enter userid and password to enter the ExternalSite munin web site";
          auth_basic_user_file /var/www/www.ExternalSite.com/.htpasswd;
          proxy_set_header Authorization $http_authorization;
          proxy_buffers 16 4k;
          proxy_buffer_size 2k;
          proxy_buffering off;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header Accept-Encoding "";
          proxy_pass http://10.10.10.18/munin;
          }       
      #######################################
      #
      # End of Reverse proxy blocks
      #
      #######################################         
      }
  </code></pre>