Skip to content

Instantly share code, notes, and snippets.

@dszymczuk
Last active July 30, 2016 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dszymczuk/43f91738e6d56f68090ca98c44b2b3ee to your computer and use it in GitHub Desktop.
Save dszymczuk/43f91738e6d56f68090ca98c44b2b3ee to your computer and use it in GitHub Desktop.
nginx vhost proxypass port
#!/bin/bash
##
## example to run, if you want pass domain.com on port 9999 :
## name-of-script.sh domain.com 9999
##
domain=$1
port=$2
nginxSitePath='/etc/nginx/sites-enabled/'
nginxInitdPath='/etc/init.d/nginx'
echo "
server {
server_name $domain;
client_max_body_size 0;
location / {
proxy_set_header X-Real_IP \$remote_addr;
proxy_set_header Host \$host;
proxy_set_header X-Forwarded_For \$proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:$port/;
}
}
" > $nginxSitePath$port-$domain
$nginxInitdPath restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment