Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)

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 at 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;

      

}

My overall goal is to access remote docker containers without modifying clients' DNS service. Can you help me with this?

 

1 Answer

0 votes
by (50.2k points)

Nginx doesn’t support sub-domains on IP address that you have used and resolving that we need to modify the client's host but in question, you have already mentioned that you don't want to change it(client’s host).

For this problem, we have one more solution (ie:-you can set nginx to redirect) for that you need to follow these commands.

location /Jenkins {

    proxy_pass http://jenkins:8080;

    ...

}

location /other-container {

    proxy_pass http://other-container:8080;

}

It would allow you to your IP address (ie:-192.168.1.2/jenkins)

One more way to achieve access by serving the containers through different ports, for that you need to follow this docker file so that you will get easily.

server {

    listen 8081;

    location / {

        proxy_pass http://jenkins:8080;

        ...

}

server {

    listen 8082;

    location / {

        proxy_pass http://other-container:8080;

        ...

    

}

After building this dockerfile you can access through port -81.

Thus, this is the way to configure Nginx to access hosted services through a subdomain of your server. And services and Nginx are instantiated with Docker-compose.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...