Sign inSign up

pam79/nginx

By pam79

Updated over 6 years ago

Dockerized NginX web server

Image
0

10K+

pam79/nginx repository overview

Nginx

Nginx is an open source reverse proxy server for HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as a Load Balancer, HTTP cache, Web Server, etc.

Nginx version: v1.16.*

Usage

  • Hosting some simple static content
    $ docker run --name nginx \
      -v /some/content:/usr/share/nginx/html:ro \
      -d pam79/nginx
    
  • Exposing external port
    $ docker run --name nginx \
      -v /some/content:/usr/share/nginx/html:ro \
      -p 8080:80 \
      -d pam79/nginx
    

    Then you can hit http://localhost:8080 or http://host-ip:8080 in your browser.

  • Complex configuration
    $ docker run --name nginx \
      -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro \
      -d pam79/nginx
    
  • Using environment variables in nginx configuration

    Out-of-the-box, nginx doesn't support environment variables inside most configuration blocks. But envsubstmay be used as a workaround if you need to generate your nginx configuration dynamically before nginx starts.

    web:
      image: pam79/nginx
      volumes:
       - ./mysite.template:/etc/nginx/conf.d/mysite.template
      ports:
       - "8080:80"
      environment:
       - NGINX_HOST=foobar.com
       - NGINX_PORT=80
      command: /bin/bash -c "envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"
    

    The mysite.template file may then contain variable references like this:

    listen ${NGINX_PORT};

  • Running nginx in read-only mode
    $ docker run -d -p 80:80 --read-only 
      -v $(pwd)/nginx-cache:/var/cache/nginx 
      -v $(pwd)/nginx-pid:/var/run pam79/nginx
    
  • Running nginx in debug mode
    $ docker run --name nginx \
      -v /host/path/nginx.conf:/etc/nginx/nginx.conf:ro \
      -d pam79/nginx nginx-debug -g 'daemon off;'
    

    Similar configuration in docker-compose.yml may look like this:

    web:
      image: pam79/nginx
      volumes:
        - ./nginx.conf:/etc/nginx/nginx.conf:ro
      command: [nginx-debug, '-g', 'daemon off;']
    
  • Monitoring nginx with Amplify

    Amplify is a free monitoring tool that can be used to monitor microservice architectures based on nginx. Amplify is developed and maintained by the company behind the nginx software.

    With Amplify it is possible to collect and aggregate metrics across containers, and present a coherent set of visualizations of the key performance data, such as active connections or requests per second. It is also easy to quickly check for any performance degradations, traffic anomalies, and get a deeper insight into the nginx configuration in general.

    In order to use Amplify, a small Python-based agent software (Amplify Agent) should be installed inside the container.

    For more information about Amplify, please check the official documentation here.

Tag summary

Content type

Image

Digest

Size

48.3 MB

Last updated

over 6 years ago

docker pull pam79/nginx