Sign inSign up

thedrhax/nginx-stateless

By thedrhax

Updated about 8 years ago

NGINX image for Docker that can be customized using the environment variables.

Image
0

937

thedrhax/nginx-stateless repository overview

Stateless NGINX for Docker

This image can be configured by modifying environment variables at container startup. Feel free to contribute ;)

Options

# PHP FPM
FPM=false
FPM_HOST=app
FPM_PORT=9000
FPM_TIMEOUT_READ=60s
FPM_TIMEOUT_SEND=60s

# Reverse proxy
PROXY=false
PROXY_PROTO=http
PROXY_HOST=app

# uWSGI
UWSGI=false
UWSGI_HOST=app
UWSGI_PORT=9000

# SSL termination
SSL=false
SSL_CERT=/ssl/cert.pem
SSL_KEY=/ssl/key.pem
SSL_TIMEOUT=5m

# Location options
LOCATION=/
LOCATION_MODE=root
LOCATION_PATH=/var/www/html
LOCATION_INDEX="index.php index.html index.htm"
LOCATION_AUTOINDEX=false

#
# Custom config lines
#

# before main `server {}`
CONFIG_GLOBAL_START_0=""
CONFIG_GLOBAL_START_1=""
CONFIG_GLOBAL_START_...=""

# after main `server {}`
CONFIG_GLOBAL_END_0=""
CONFIG_GLOBAL_END_1=""
CONFIG_GLOBAL_END_...=""

# before main `location {}`
CONFIG_SERVER_0=""
CONFIG_SERVER_1=""
CONFIG_SERVER_...=""

# inside main `location {}`
CONFIG_LOCATION_0=""
CONFIG_LOCATION_1=""
CONFIG_LOCATION_...=""

Examples

Static content only
docker run -it --rm -v www:/var/www/html -p 80:80 thedrhax/nginx-stateless
Static content with autoindex
docker run -it --rm -v www:/var/www/html -p 80:80 -e LOCATION_AUTOINDEX=true -e LOCATION_INDEX="" thedrhax/nginx-stateless
Static content + PHP (Piwik, ownCloud, etc.)
docker run -it --rm -v www:/var/www/html -p 80:80 -e FPM=true -e FPM_HOST=your.fpm.host thedrhax/nginx-stateless
Reverse proxy
docker run -it --rm -p 80:80 -e PROXY=true -e PROXY_HOST=another.server thedrhax/nginx-stateless
SSL termination
docker run -it --rm -v ssl:/ssl -p 443:443 -e SSL=true -e SSL_CERT=/path/to/cert.pem -e SSL_KEY=/ssl/key.pem thedrhax/nginx-stateless

You can also combine SSL termination with all previous examples.

Redirect by Host
docker run -it --rm -p 80:80 -e CONFIG_GLOBAL_END_0="server { server_name b.example.com; return 301 \$scheme://a.example.com$request_uri; }" thedrhax/nginx-stateless

Redirect all unknown Hosts

docker run -it --rm -p 80:80 -e CONFIG_GLOBAL_START_0="server { return 301 \$scheme://a.example.com$request_uri; }" -e CONFIG_SERVER_0="server_name a.example.com;" thedrhax/nginx-stateless
Add custom config lines

You can add custom lines to server{} and location{} blocks by setting CONFIG_SERVER_* and CONFIG_LOCATION_*. Number of the first line must be 0.

docker run --it --rm -v www:/var/www/html -p 81:81 -e CONFIG_SERVER_0="listen 81;" thedrhax/nginx-stateless

Tag summary

Content type

Image

Digest

Size

8.4 MB

Last updated

about 8 years ago

docker pull thedrhax/nginx-stateless