Configure Subdomains, Nginx-proxy and Docker-compose

0 votes

I want to configure Nginx to access hosted services with 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.

It is not working working a top domain name, but not locally with for example 192.168.1.2.

Can anyone help me with this query?

Thanks

May 1, 2018 in DevOps on Cloud by Atul
• 10,240 points
1,853 views

2 answers to this question.

0 votes

Try any of the following methods:

you can just set your nginx to redirect like so:

location /jenkins {
    proxy_pass http://jenkins:8080;
    ...
}

location /other-container {
    proxy_pass http://other-container:8080;
}

which would allow you to access jenkins at 192.168.1.2/jenkins


Or you can serve your different containers through different ports. E.g:

server {
    listen 8081;
    location / {
        proxy_pass http://jenkins:8080;
        ...
    }
}

server {
    listen 8082;
    location / {
        proxy_pass http://other-container:8080;
        ...
    }
}

And then you can access Jenkins on port address 192.168.1.2:8081/.

I hope it will help you resolve your query.

answered May 1, 2018 by shubham
• 6,890 points
0 votes

If you are already using docker-compose I recommend using the jwilder nginx-proxy container.

https://github.com/jwilder/nginx-proxy

This allows you to add unlimited number of web service containers to the backend of the defined nginx proxy, for example:

nginx-proxy:
  image: jwilder/nginx-proxy
  ports:
    - "80:80"
    - "443:443"
  volumes:
    - "/etc/nginx/vhost.d"
    - "/usr/share/nginx/html"
    - "/var/run/docker.sock:/tmp/docker.sock:ro"
    - "nginx_certs:/etc/nginx/certs:rw"
nginx:
  build:
   context: ./docker/nginx/
   dockerfile: Dockerfile
  volumes_from:
     - data
  environment:
     VIRTUAL_HOST: www.host1.com
nginx_2:
  build:
   context: ./docker/nginx_2/
   dockerfile: Dockerfile
  volumes_from:
     - data
  environment:
     VIRTUAL_HOST: www.host2.com
apache_1:
  build:
   context: ./docker/apache_1/
   dockerfile: Dockerfile
  volumes_from:
     - data
  environment:
     VIRTUAL_HOST: www.host3.com
answered Aug 3, 2018 by Nilesh
• 6,920 points

Related Questions In DevOps on Cloud

+4 votes
2 answers

unable to get subdomain of URL in NGINX

You just need to add .+ after ...READ MORE

answered Oct 11, 2018 in DevOps on Cloud by lina
• 8,160 points
686 views
+2 votes
3 answers

can't make nginx try_files to work with default_index.html

Here's another convenient use of try_files, as ...READ MORE

answered Oct 18, 2018 in DevOps on Cloud by Hannah
• 17,060 points
520 views
0 votes
1 answer

How can I remove a port from url for node app using nginx

If you run your node server on ...READ MORE

answered Apr 10, 2018 in DevOps on Cloud by ajs3033
• 7,280 points
619 views
0 votes
1 answer

High availability (HA) website load balanced across both Azure and AWS?

DNS load balancing is the practice of ...READ MORE

answered Jul 6, 2018 in DevOps on Cloud by Kalgi
• 45,780 points
38 views
0 votes
2 answers

Nginx Request redirection one container to another

try adding a / at the end ...READ MORE

answered Oct 25, 2018 in DevOps on Cloud by Haseeb
58 views
0 votes
1 answer

Deploying Code and Managing configuration with Terraform

Try one of these for your first ...READ MORE

answered Jul 23, 2018 in DevOps on Cloud by Kalgi
• 45,780 points
680 views
0 votes
1 answer
0 votes
1 answer

Deploy Docker Containers from Docker Cloud

To solve this problem, I followed advice ...READ MORE

answered Sep 3, 2018 in AWS by Priyaj
• 56,960 points
251 views
0 votes
1 answer