Created
November 25, 2014 00:36
-
-
Save simonw/5f2b52037b0f6ea8621d to your computer and use it in GitHub Desktop.
Run nginx and serve the current directory contents (without needing a config file), logging to stdout/stderr
This file contains hidden or 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 | |
| if [ $# -ge 1 ]; then | |
| PORT=$1 | |
| else | |
| PORT=8000 | |
| fi | |
| CONF_PATH=$(mktemp /tmp/nginx-tmp-config.XXXXXXXX) || { echo "Failed to create temp file"; exit 1; } | |
| cat > $CONF_PATH <<- EOF | |
| daemon off; | |
| events { | |
| worker_connections 1024; | |
| } | |
| http { | |
| access_log /dev/stdout; | |
| error_log /dev/stderr; | |
| types { | |
| text/html html htm shtml; | |
| text/css css; | |
| image/gif gif; | |
| image/jpeg jpeg jpg; | |
| application/javascript js; | |
| } | |
| server { | |
| listen $PORT; | |
| index index.html; | |
| root .; | |
| } | |
| } | |
| EOF | |
| echo "Running on http://127.0.0.1:$PORT/" | |
| nginx -p `pwd` -c $CONF_PATH | |
| # Cleanup when the user hits Ctrl+C | |
| rm $CONF_PATH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment