DEV Community

Setting up a Reverse-Proxy with Nginx and docker-compose

Dominik Weber on July 23, 2018

Nginx is a great piece of software that allows you to easily wrap your application inside a reverse-proxy, which can then handle server-related asp...
Collapse
 
claypaenguin profile image
Claypenguin

Hi,

nice article. There's only one thing I'm wondering.

Is the expose: "80" really needed? Because according to the docker/docker-compose docs containers that are connected to the same network should be exposed to each other. Or am I missing something here?

cheers

Collapse
 
michaelswerston profile image
MichaelSwerston

Very nice article, I find the amount of information on this website astonishing you can learn practically anything on the web these days. I covered some alternative use cases for residential proxies on my blog.

Collapse
 
assender profile image
assender

Very great and detailed article, which is easy to follow! Kudos for that! I would also add that it's not only important to know "how to" but also which proxy services to use. I reviewed some of the best residential proxy providers in the market and everyone are welcome to check that out if they need some clearance about it.

Collapse
 
samayo profile image
samayo

Hi, nice guide.

Does this work for localhost though? As in, if I want to host multiple sites in my local machine just for development purposes. I say this because, I have used few guides like the one your wrote, and they all worked on my VPS but not in localhost

Collapse
 
groomedgorilla profile image
Julian Zammit

Hi Dominik,

Great article! Thanks for that.

I've seen others requesting the codebase for this, but if you could share the final version of the nginx.conf and docker-compose.yml files that would be a great start to solidifying people's understanding of this topic.

I know it would help me loads :)

Cheers!

Collapse
 
domysee profile image
Dominik Weber

Hi Julian,

sorry it took so long, I'm sure you already figured it out, whatever problem you had.

But for what it's worth, I've added them now :)

Collapse
 
theincognitotech profile image
theincognitotech

Hi,

Great article, Dominik! Thanks for that. I would also recommend checking my review, put a lot of effort into it trying to review one proxy provider :)

Collapse
 
mornedup profile image
Morne Du Preez

hi

Like the article as it is clear and easy to follow.

I have followed your instructions as in the article up until the ssh cert setup.

So i have some issue where the reverse proxy complains that it does not have "events" in the configuration file.

Is there something that i missed somewhere?

side note:
your image was not available to use so i just replaced it with the hello-world image used to test if docker is working.

Collapse
 
domysee profile image
Dominik Weber

Hi, glad that it helped!

You probably already figured it out, you have to have an empty events section in the nginx.conf file.

I've added the complete nginx.conf and docker-compose.yml files at the end, which includes the events section.

I didn't want to go into the details of nginx, but this is definitely something I should've mentioned.

Sorry it took so long for me to reply!

Collapse
 
dneary profile image
Dave Neary

Hi,

How do you know if the cache works? I added an X-Cached header to HTTP responses with $upstream_cache_status but it is almost always MISS, even for static resources like Javascript files or images. I suspect there is a permission issue with the nginx process writing to the proxy_cache_path, but I don't know how to fix it. Should I use a volume?

Thanks,
Dave.

Collapse
 
aliuosio profile image
Osiozekhai Aliu • Edited

Servus Dominik,

nice well explained and short article...
can the whole code been seen somewhere in the web?

regards
Osio

Collapse
 
domysee profile image
Dominik Weber

Hi Osio,

Since it is split between the Nginx config, docker compose config, some console commands and cronjobs, I don't have any one file that contains all of it.

But I might create some example configs and a bash script that automates the setup when I get the time.

Dominik

Collapse
 
aliuosio profile image
Osiozekhai Aliu

Servus Dominik,

ich hab schon mal angefangen. Vielleicht kannst Du Dir ein For machen.

github.com/aliuosio/docker-web-proxy

Collapse
 
domysee profile image
Dominik Weber

Hi, I've (finally!) added full docker-compose.yml and nginx.conf files.

Hope this helps.

Collapse
 
usuario001 profile image
José Manuel

Thank, I'm finally understanding how proxy works

Collapse
 
kyawthetkhineais profile image
kyawthetkhineais

with container_name is set in docker-compose, the containers cannot be replicated in swarm mode? So how to customize the docker-compose.yml to replicate the containers in docker-swarm mode?

Collapse
 
fadiquader profile image
fadiquader

Wow!
Thank you Dominik.

Collapse
 
trevdev profile image
Trev

It's nice to see a guide that doesn't involve nginx-proxy (jwilder) and letsencrypt-companion.

Collapse
 
andypotter profile image
Andrew Potter

Excellent post. Exactly what I needed

Thanks

Collapse
 
boscorelly profile image
Camille Ollié

Thanks, you helped me a lot with docker :)