grimoire

personal wiki
git clone git://git.pyratebeard.net/grimoire.git
Log | Files | Refs

nginx.md (1641B)


      1 # nginx
      2 
      3 ## nginx-proxy
      4 the following details how to use `nginx-proxy` to host multiple docker containers ([nginx-proxy guide][])
      5 
      6 - create docker network
      7 	```
      8 	docker network create nginx-proxy
      9 	```
     10 - install nginx-proxy container
     11 	```
     12 	docker run -d --name nginx-proxy \
     13 		-p 80:80 \
     14 		--net nginx-proxy \
     15 		-v /var/run/docker.sock:/tmp/docker.sock \
     16 		jwilder/nginx-proxy
     17 	```
     18 
     19 ### letsencrypt companion
     20 in order to use the [letsencrypt companion][] container with nginx-proxy we need to modify the nginx-proxy run command slightly
     21 
     22 	```
     23 	docker run -d --name nginx-proxy \
     24 		-p 80:80 -p 443:443 \
     25 		--net nginx-proxy \
     26 		-v /etc/nginx/certs \
     27 		-v /etc/nginx/vhost.d \
     28 		-v /usr/share/nginx/html \
     29 		-v /var/run/docker.sock:/tmp/docker.sock:ro \
     30 		jwilder/nginx-proxy
     31 	```
     32 	
     33 then we can run the `letsencrypt-nginx-proxy-companion` container
     34 
     35 	```
     36 	docker run -d --name nginx-proxy-letsencrypt \
     37 		--volumes-from nginx-proxy \
     38 		-v /var/run/docker.sock:/var/run/docker.sock:ro \
     39 		-e "DEFAULT_EMAIL=root@pyratebeard.net" \
     40 		jrcs/letsencrypt-nginx-proxy-companion
     41 	```
     42 
     43 to start the application containers add the `VIRTUAL_HOST` and `LETSENCRYPT_HOST` variables
     44 _using my log container as an example_
     45 	
     46 	```
     47     docker run -d --name "$CONTAINER_NAME" \
     48         --expose 1313 \
     49         --net nginx-proxy \
     50         -e VIRTUAL_HOST=log.pyratebeard.net \
     51         -e LETSENCRYPT_HOST=log.pyratebeard.net \
     52         -v $(pwd):/src \
     53         $CI_REGISTRY_IMAGE
     54 	```
     55 
     56 [nginx-proxy guide]: https://blog.ssdnodes.com/blog/host-multiple-websites-docker-nginx/
     57 [letsencrypt companion]: https://github.com/JrCs/docker-letsencrypt-nginx-proxy-companion