Subdomains, Nginx-proxy and Docker-compose

Viewed 19907

I'm looking for a way to configure Nginx to access hosted services through a subdomain of my server. Those services and Nginx are instantiated with Docker-compose.

In short, when typing jenkins.192.168.1.2, I should access to Jenkins hosted on 192.168.1.2 redirected with Nginx proxy.

A quick look of what I currently have. It doesn't work without a top domain name, so it works fine on play-with-docker.com, but not locally with for example 192.168.1.2.

server {
    server_name jenkins.REVERSE_PROXY_DOMAIN_NAME;
        location / {
            proxy_pass http://jenkins:8080;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Proto $scheme;
            proxy_set_header X-Forwarded-Host $host:$server_port;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
}

To have a look of what I want: https://github.com/Ivaprag/devtools-compose

My overall goal is to access remote docker containers without modifying clients' DNS service.

3 Answers

I was trying to configure subdomains in nginx (host), for two virtualhosts in one LXC container.

The way it worked for me:

For apache (in the container), I created two virtual hosts: one in port 80 and the other one in port 90.
For enabling port 90 in apache2 (container), it was necessary to add the line "Listen 90" below "Listen 80" in /etc/apache2/ports.conf

For NGINX (host machine), configured two DOMAINS, both in port 80 creating independent .conf files in /etc/nginx/sites-available. Created symbolic link for each file to /etc/nginx/sites-enabled.

In the first NGINX myfirstdomain.conf file, redirect to http://my.contai.ner.ip:80.

In the second NGINX myseconddomain.conf file, redirect to http://my.contai.ner.ip:90

That was it for me !

Related