This repo is a simple Nginx proxy server you can run in Docker.
Pull image
docker pull machy8/docker-nginx-proxy-server
Required network
docker network create proxy-server
-
Open your console and run
docker network create proxy-server
-
Create a docker-compose.yml file for the proxy-server
version: '3'
services:
server:
container_name: proxy-server
image: machy8/docker-nginx-proxy-server
volumes:
- ./sites.d/test-web:/etc/nginx/sites.d/test-web
- ./certificates:/etc/letsencrypt
- ./log:/var/log/nginx
networks:
- proxy-server
ports:
- "80:80"
- "443:443"
networks:
proxy-server:
external:
name: proxy-server
- Create a directory /sites.d/test-web (example with certificates bellow)
- docker-compose.yml
- sites.d
- test-web
- test-web.conf
- Create a configuration file (for example test.com.conf) in the hosts directory
server {
listen 80;
server_name localdev.test.com test.com;
proxy_redirect off;
proxy_set_header Host $host;
location / {
proxy_pass http://test-web/; # test-web is the name of the container where the request will be redirected
}
}
- Connect containers you want to connect to proxy server to the proxy-server network
version: "3"
services:
web:
container_name: test-web
image: nginx:alpine
networks:
- proxy-server
networks:
proxy-server: # This is the name for network used in THIS configuration file
external: # This says, that the network is external (not within this docker-compose.yml)
name: proxy-server # This s the name of the external network
- (optional) Edit your hosts file
127.0.0.1 localhost
127.0.0.1 localdev.test.com test.com
- Build and start the container with your test web
- Build and start the container with proxy-server
- Open browser and connect to http://localdev.test.com
- Proxy server already contains certbot
- Nginx is configured to redirect all .well-known paths to the
/var/www/html
directory in order to allow Let's Encrypt to check and generate the certificates
Note In case you dont want to have certbot on localhost you need to remove the config. You can achieve that by creating a new Dockerfile in which you will remove it.
FROM machy8/docker-nginx-proxy-server
RUN rm /etc/nginx/conf.d/certbot.conf