Skip to content

rwecho/nginx-cert

Repository files navigation

NginxWithCert

NginxWithCert is a nginx docker container with automatic certbot ssl certificates. It bases on official nginx image with crontab and cerbot.

Declaretion

This is not a pull-run script. Because some sensitive information is ignored by .gitignore.

Installation

Nginx is a extensible host framework. With conf.d folder we can serve multiple domain-sites.

  1. According official document of nginx sit. We mount ./etc/nginx/conf.d to /etc/nginx/confid in container.

    server {
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html;
        server_name example.com www.example.com;
    }
  2. Run in dock Firstly build docker with Dockerfile with a name. For example: rwecho/nginx-autocert:latest

    docker run \
        --name nginx-cert\
        -d \
        -e DOMAINS="example.com,www.example.com" \
        -e EMAIL="example@example.com" \
        -e COUNTRY="GB \
        -v ./etc/nginx/conf.d:/etc/nginx/conf.d \
        -v ./etc/letsencrypt:/etc/letsencrypt \
        -p 80:80 \
        -p 443:443 \
        rwecho/nginx-autocert:latest
    
  3. Run in docker-compose

        version: '2.0'
        services:
        nginx:
            image: 'rwecho/nginx-autocert:latest'
            container_name: 'nginx-autocert'
            ports:
            - '80:80'
            - '443:443'
            volumes:
            - ./etc/nginx/conf.d:/etc/nginx/conf.d
            - ./etc/letsencrypt:/etc/letsencrypt
            restart: always
            environment:
            - EMAIL=example@example.com
            - DOMAINS=example.com,www.example.ecm
            - COUNTRY=GB
        ```
    
    
  4. Environments

    • DOMAINS pass to cetbot s -d/--domains, comma-separated list of the domains
    • EMAIL pass to cetbot -m for Certbot notifications.
    • COUNTRY with your two letter country code

References:

autocert Using let's cencrypt ssl/tls with nginx

About

Dockerize nginx with contrab and cerbot.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published