Created
April 28, 2015 16:34
-
-
Save gvarela/6d77cdea9eeb06dc9328 to your computer and use it in GitHub Desktop.
Mimic pow and powder by generating a local nginx conf file that is symlinked to the homebrew nginx configuration. requires dnsmasq and nginx to be installed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
rm .nginx.conf | |
while [[ $# > 1 ]] | |
do | |
key="$1" | |
case $key in | |
-p|--port) | |
PORT="$2" | |
shift | |
;; | |
-n|--name) | |
NAME="$2" | |
shift | |
;; | |
--public-path) | |
PUBLICPATH="$2" | |
shift | |
;; | |
*) | |
# unknown option | |
;; | |
esac | |
shift | |
done | |
if [[ -z "$PUBLICPATH" ]] | |
then | |
PUBLICPATH=`pwd` | |
fi | |
( | |
cat <<CONF | |
upstream $NAME { | |
server 127.0.0.1:$PORT; | |
} | |
server { | |
listen 80; | |
server_name $NAME.dev; | |
root $PUBLICPATH/public; | |
try_files \$uri/index.html \$uri.html \$uri @app; | |
location @app { | |
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for; | |
proxy_set_header Host \$http_host; | |
proxy_redirect off; | |
proxy_pass http://$NAME; | |
} | |
} | |
CONF | |
) > .nginx.conf | |
ln -sf `pwd`/.nginx.conf /usr/local/etc/nginx/sites-enabled/$NAME.dev | |
sudo nginx -s reload | |
echo "Start your server on port $PORT and go to http://$NAME.dev" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
based on this article http://zaiste.net/2013/03/serving_apps_locally_with_nginx_and_pretty_domains/