D
D
Dmitry2018-07-12 14:48:24
Nginx
Dmitry, 2018-07-12 14:48:24

How is regex handled in nginx location?

Hello,
Playing with ELK stack in docker, I decided to get Kibana on external nginx. It is necessary to do it with the help of location and I came across the fact that if I add a working location for Kibana (it will be lower) - the others that already exist break.
I add this:

location ~ (|/app/kibana|/bundles/|/status|/plugins|/elasticsearch/|)  {
  proxy_pass http://192.168.1.10:5601;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        rewrite /(.*)$ /$1 break;
    }

The problem, as I understand it, is in the construction (|/app/kibana|/bundles/|/status|/plugins|/elasticsearch/|) - explain to me why it starts and ends with an OR sign - " | " , how is this handled location.
PS And it stops working, for example, such a location
location /portainer/ {
  proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_pass http://portainer/;
    }

    location ^~ /portainer/api/websocket/ {
  proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_http_version 1.1;
        proxy_pass http://portainer/api/websocket/;
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nurlan, 2018-07-12
@q2digger

Next, nginx checks the locations given by regular expressions in the order in which they appear in the configuration file. On the first match, the search stops and nginx uses the matched location.

How nginx handles requests

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question