V
V
voker20052019-11-12 16:46:53
Nginx
voker2005, 2019-11-12 16:46:53

How to proxy for a specific location in Nginx?

Hello,
How can I make Nginx proxy for a specific location ? I need Grafana to open when accessing the https://corp.domain.com domain , and Prometheus to open when accessing the https://corp.domain.com/prom/ link . Now I have this config, it does not work :
5dcaba668ffc1264804255.jpeg

server {
        server_name     corp.domain.com;

        ............ Тут часть от Let's Encrypt сертификата ............

        location / {
                proxy_pass http://localhost:3000;
                gzip                    off;
                proxy_buffers           8 32k;
                proxy_buffer_size       64k;
                proxy_request_buffering off;
                proxy_read_timeout      300;
                proxy_redirect          off;
                proxy_http_version      1.1;
                proxy_set_header        Host                    $http_host;
                proxy_set_header        X-Real-IP               $remote_addr;
                proxy_set_header        X-Forwarded-For         $proxy_add_x_forwarded_for;
                proxy_set_header        X-Forwarded-Proto       $scheme;
                proxy_set_header        X-Forwarded-Ssl         on;
                proxy_set_header        X-Frame-Options         SAMEORIGIN;
                proxy_set_header        Upgrade                 $http_upgrade;
                proxy_set_header        Connection              "upgrade";
        }

        location /prom {
                proxy_pass http://localhost:9090/;
        }

  ............ Тут тоже часть от Let's Encrypt сертификата ..... например переадресация c http на https.......

}

Now it works like this, when you try to open https://corp.domain.com/prom/ , Grafana opens , as if there is no such rule with location in nginx at all. No errors are written in the logs, when visiting the site, in the logs there is a "normal" 302nd redirect to grafana.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dmitry, 2019-11-12
@Oldshelf

Try to specify the location more specifically:
location = /prom {

D
Dimonchik, 2019-11-12
@dimonchik2013

nginx.org/ru/docs/http/request_processing.html
you have two hosts - corp.host and host
so configure them
why do you put host settings in corp.host ?
https://www.8host.com/blog/nastrojka-virtualnyx-xo...

G
grinat, 2019-11-13
@grinat

Well, nginx redirects the request as it is, and it seems that prometheus decides that this is an invalid page and through a 302 redirect redirects to the main domain where the grafana is located, because of this it seems to you that it does not work. You need to specify the host in the prometheus settings as https://corp.domain.com/prom/ or cut down the headers via proxy_pass_request_headers off and manually specify the path there, but I think it won’t work anyway, when you click on any link, it will toss into the graphana.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question