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
8,646 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
• 7,340 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
• 7,060 points

Related Questions In DevOps on Cloud

0 votes
1 answer

How to use the pipeline setup and deploy the war file using the ansible,docker and kubernettes

Hi@Venkata, You can create an Ansible-Playbook to deploy ...READ MORE

answered Sep 1, 2020 in DevOps on Cloud by MD
• 95,460 points
1,053 views
+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,220 points
4,885 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
• 18,520 points
5,247 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,300 points
4,030 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
• 52,350 points
670 views
+2 votes
1 answer
+2 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
• 58,020 points
2,718 views
+1 vote
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP