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:29] – 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 98: | Line 106: | ||
===== Pratical Example ===== | ===== Pratical Example ===== | ||
- | So a sample | + | ==== Making the Reverse Proxy ==== |
+ | |||
+ | Let's go ahead and create our folder and create our 2 required files, the docker-compose.yml | ||
+ | |||
+ | <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 | ||
<code bash> | <code bash> | ||
Line 131: | Line 153: | ||
container_name: | container_name: | ||
expose: | expose: | ||
- | | + | |
volumes: | volumes: | ||
- dokuwiki_data:/ | - dokuwiki_data:/ | ||
Line 138: | Line 160: | ||
- dokuwiki_lib-tpl:/ | - dokuwiki_lib-tpl:/ | ||
- dokuwiki_logs:/ | - 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 " | ||
+ | |||
</ | </ | ||