Advertisement
METAJIJI

nginx create vhost

Jul 2nd, 2015
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.04 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. craete_nginx_vhost() {
  4.     # Example call: craete_nginx_vhost example.org 10.10.3.1:80
  5.     [ -z "$1" -o -z "$2" ] && echo 'ERROR: $1 or $2 must be set!' && exit 1
  6.     local vhostname=$1
  7.     local backend=$2
  8.  
  9.     cat > /etc/nginx/sites-available/${vhostname}.conf <<_EOF_
  10. server {
  11.         listen 80;
  12.         server_name $vhostname;
  13.  
  14.         include common.conf;
  15.  
  16.         client_body_timeout 300;
  17.         client_max_body_size 1500m;
  18.  
  19.         location / {
  20.                 proxy_pass http://$backend;
  21.                 proxy_buffering on;
  22.                 proxy_next_upstream error timeout invalid_header http_500 http_502 http_503;
  23.  
  24.                 proxy_read_timeout 300;
  25.  
  26.                 ### Set headers ####
  27.                 proxy_set_header Host \$host;
  28.                 proxy_set_header X-Real-IP \$remote_addr;
  29.                 #proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
  30.  
  31.                 ### By default we don't want to redirect it ####
  32.                 proxy_redirect off;
  33.         }
  34.  
  35.         access_log /var/log/nginx/${vhostname}_access.log;
  36.         error_log /var/log/nginx/${vhostname}_error.log;
  37. }
  38. _EOF_
  39. }
  40.  
  41. # For example call function:
  42. craete_nginx_vhost example.org 10.10.3.1:80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement