Advertisement
rockdrilla

generate nginx config for HTTPS->HTTP frontend

Nov 23rd, 2013
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.66 KB | None | 0 0
  1. #!/bin/bash
  2. domain=domain.com
  3. declare -A map
  4. map[adm]=8021
  5. map[web]=8022
  6. map[cms]=8023
  7.  
  8. cp proxy{,.bak$(date +'%y%m%d.%H%M%S')} 2>/dev/null
  9. : > proxy
  10.  
  11. for i in ${!map[@]}; do
  12.     fqdn=$i.${domain}
  13.     cat >> proxy <<EOF
  14. server { # 127.0.0.1:${map[$i]}
  15.     listen 443 ssl;
  16.     server_name ${fqdn};
  17.     ssl_certificate      cert/${fqdn}.crt;
  18.     ssl_certificate_key  cert/${fqdn}.key;
  19.     location / {
  20.         proxy_pass http://127.0.0.1:${map[$i]};
  21.         proxy_set_header Host \$host;
  22.         proxy_set_header X-Real-IP \$remote_addr;
  23.     }
  24. }
  25. server {
  26.     listen 80;
  27.     server_name ${fqdn};
  28.     return 301 https://${fqdn}\$request_uri;
  29. }
  30. EOF
  31. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement