Skip to content

christiandesantis/nginx-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nginx Docker Setup

This repository contains a Docker setup for running Nginx with custom configurations and environment variables.

Prerequisites

  • Docker
  • Docker Compose

Setup

  1. Clone the repository:

    git clone https://github.com/christiandesantis/nginx-docker.git nginx
    cd nginx
  2. Copy the .env.example file to .env and adjust the variables accordingly:

    cp .env.example .env

    Edit the .env file to set the appropriate values for your environment:

    DOMAIN_NAME=example.com
    HOME=/home/your-username
    SSL_CERT=/path/to/your/fullchain.pem
    SSL_KEY=/path/to/your/privkey.pem
    MAIN_DIST=/path/to/your/dist
  3. Make the ./reload.sh and ./restart.sh scripts executable:

    chmod +x reload.sh restart.sh

Usage

Build and Start the Containers

To build and start the Nginx container, run:

docker compose up --build -d

Reload Nginx Configuration

To reload the Nginx configuration inside the container, run:

./reload.sh

Restart Nginx

To restart Nginx inside the container, run:

./restart.sh

Stop the Containers

To stop the Nginx container, run:

docker compose down

File Structure

  • .env: Environment variables file.
  • .env.example: Example environment variables file.
  • docker-compose.yml: Docker Compose configuration file.
  • Dockerfile: Dockerfile for building the Nginx image.
  • nginx.conf: Custom Nginx configuration file.
  • reload.sh: Script to reload Nginx configuration inside the container.
  • restart.sh: Script to restart Nginx inside the container.

Volumes

The following volumes are mounted in the Nginx container:

  • ./nginx.conf:/etc/nginx/conf.d/default.conf:ro: Custom Nginx configuration file.
  • /var/www:/var/www:ro: Web root directory.
  • ${HOME-/home}:/home/user:ro: Home directory.
  • ${MAIN_DIST-/usr/share/nginx/html}:/usr/share/nginx/html:ro: Distribution directory.
  • ${SSL_CERT}:/etc/ssl/certs/fullchain.pem:ro: SSL certificate.
  • ${SSL_KEY}:/etc/ssl/private/privkey.pem:ro: SSL private key.

Networks

The Nginx container is connected to the nginx-network network.

Ports

The following ports are exposed:

  • 80:80: HTTP
  • 443:443: HTTPS

License

This project is licensed under the MIT License.

About

Nginx Docker Starter Setup

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages