Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
computer_science:docker:docker_nginx_reverse_proxy [2020/07/30 09:23] – carlossousa | computer_science:docker:docker_nginx_reverse_proxy [2023/12/01 12:07] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Nginx as Reverse Proxy for Docker Containers ====== | ====== Nginx as Reverse Proxy for Docker Containers ====== | ||
+ | |||
+ | **Important Notice:** | ||
+ | |||
+ | This is an example for a Reverse Proxy. I will be using Traefik to [[: | ||
+ | |||
+ | ---- | ||
My setup for the docker env. is the same as described on [[: | My setup for the docker env. is the same as described on [[: | ||
Line 20: | Line 26: | ||
- A Nginx config | - A Nginx config | ||
- | ===== Sample Nginx Reverse Proxy configuration ===== | + | ===== Sample Nginx Reverse Proxy - nginx.conf - configuration ===== |
- | A sample nginx reverse proxy setup would like something like this: | + | A sample nginx reverse proxy config file - nginx.conf - would like something like this: |
<code bash> | <code bash> | ||
Line 58: | Line 64: | ||
</ | </ | ||
- | ===== A Nginx Reverse-Proxy sample docker-compose.yml | + | ===== A Nginx Reverse-Proxy sample docker-compose.yml ===== |
+ | |||
+ | would be something like: | ||
<code bash> | <code bash> | ||
Line 92: | Line 100: | ||
expose: | expose: | ||
- " | - " | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | ===== Pratical Example ===== | ||
+ | |||
+ | ==== Making the Reverse Proxy ==== | ||
+ | |||
+ | Let's go ahead and create our folder and create our 2 required files, the docker-compose.yml and the nginx.conf. Navigate to your desired folder and run: | ||
+ | |||
+ | <code bash> | ||
+ | mkdir nging-reverseproxy | ||
+ | touch docker-compose.yml | ||
+ | touch nginx.conf | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | Using your favourite method, deploy your **docker-compose.yml **setup. I will be using the good old ' | ||
+ | |||
+ | My configuration would be as follows: | ||
+ | |||
+ | <code bash> | ||
+ | version: ' | ||
+ | volumes: | ||
+ | dokuwiki_data: | ||
+ | external: true | ||
+ | dokuwiki_conf: | ||
+ | external: true | ||
+ | dokuwiki_lib-plugins: | ||
+ | external: true | ||
+ | dokuwiki_lib-tpl: | ||
+ | external: true | ||
+ | dokuwiki_logs: | ||
+ | external: true | ||
+ | |||
+ | services: | ||
+ | nginx: | ||
+ | image: nginx: | ||
+ | container_name: | ||
+ | volumes: | ||
+ | - ./ | ||
+ | - ./ | ||
+ | - ./ | ||
+ | - / | ||
+ | ports: | ||
+ | - 80:80 | ||
+ | - 443:443 | ||
+ | |||
+ | dokuwiki: | ||
+ | image: ' | ||
+ | container_name: | ||
+ | expose: | ||
+ | - ' | ||
+ | volumes: | ||
+ | - dokuwiki_data:/ | ||
+ | - dokuwiki_conf:/ | ||
+ | - dokuwiki_lib-plugins:/ | ||
+ | - dokuwiki_lib-tpl:/ | ||
+ | - dokuwiki_logs:/ | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | And now we edit the **nginx.conf **to point back to our DokuWiki. Note that I will already configure a sub-domain and a main domain, which at the moment would both point to the same container, but once we make [[: | ||
+ | |||
+ | <code bash> | ||
+ | events { | ||
+ | |||
+ | } | ||
+ | |||
+ | http { | ||
+ | #error_log / | ||
+ | client_max_body_size 20m; | ||
+ | |||
+ | proxy_cache_path / | ||
+ | |||
+ | server { | ||
+ | server_name wiki.carlossousa.tech; | ||
+ | |||
+ | location / { | ||
+ | include / | ||
+ | proxy_pass http:// | ||
+ | } | ||
+ | } | ||
+ | |||
+ | server { | ||
+ | server_name carlossousa.tech; | ||
+ | |||
+ | location / { | ||
+ | include / | ||
+ | proxy_pass http:// | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | And finally we will once again create a **backup_to_tar.sh **so we can backup our nginx Reverse Proxy setup: | ||
+ | |||
+ | <code bash> | ||
+ | #!/bin/bash | ||
+ | SOURCE_PATH="/ | ||
+ | BACKUP_PATH="/ | ||
+ | BACKUP_NAME=" | ||
+ | tar cvf " | ||