From 4164b11fa9d2cd7e798e7653d9d109ac08047b1b Mon Sep 17 00:00:00 2001 From: pablo Date: Sat, 29 Jan 2022 19:47:39 +0100 Subject: [PATCH] Made the data folder an envvar --- nginx/subdomains_and_reverse_proxy.md | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 nginx/subdomains_and_reverse_proxy.md diff --git a/nginx/subdomains_and_reverse_proxy.md b/nginx/subdomains_and_reverse_proxy.md new file mode 100644 index 0000000..57e4ad7 --- /dev/null +++ b/nginx/subdomains_and_reverse_proxy.md @@ -0,0 +1,39 @@ +# Subdomain and reverse proxy + +Now that I have my own domain, life is pretty cool. I can leave behind the +harsh days of typing my server IPs in the browser, and point to my services +with nice names. + +Through porkbun's UI, I can point my domain name to any ip. But, I can't +specify anything related to ports! After some research, I found out what I +could do is to specify different subdomains in porkbun, and set up a reverse +proxy in nginx to direct traffic thanks to this subdomains. Basically, I tell +porkbun to direct each subdomain to my IP, and then I set up the nginx running +in navaja to point to different docker containers depending on the subdomain +that is getting requested. + +This is an example on how to set the reverse proxy config in nginx: + +``` + server { + listen 80; + server_name git.contrapeso.xyz; + location / { + proxy_set_header Host $host; + proxy_pass http://gogs_web_1:3000; + proxy_redirect off; + } + } +``` + +Where `git.contrapeso.xyz` is the subdomain and the contents of `proxy_pass` is +where requests should be redirected. + +Something not obvious to take into account: since my nginx is running within a +docker container, networking within navaja is a bit tricky. The way I got it +right is to: + +- Make sure that the nginx container is running in the same network as the one + where traffic should be redirected. +- Redirect using the container name and the listening port _within_ the + container, not the redirecting one in the host. \ No newline at end of file