This repository contains a Docker setup for running Nginx with custom configurations and environment variables.
- Docker
- Docker Compose
-
Clone the repository:
git clone https://github.com/christiandesantis/nginx-docker.git nginx cd nginx -
Copy the
.env.examplefile to.envand adjust the variables accordingly:cp .env.example .env
Edit the
.envfile 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
-
Make the
./reload.shand./restart.shscripts executable:chmod +x reload.sh restart.sh
To build and start the Nginx container, run:
docker compose up --build -dTo reload the Nginx configuration inside the container, run:
./reload.shTo restart Nginx inside the container, run:
./restart.shTo stop the Nginx container, run:
docker compose down.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.
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.
The Nginx container is connected to the nginx-network network.
The following ports are exposed:
80:80: HTTP443:443: HTTPS
This project is licensed under the MIT License.