U
U
uSide2014-10-17 16:57:57
Nginx
uSide, 2014-10-17 16:57:57

How to arrange location in nginx for "all other urls" case?

I have the following config:

location ^~ /api {
    if ($http_cookie ~ 'sid'){
        proxy_pass http://localhost:300;
        break;
    }

    return 403;
}

location ^~ /auth {
    proxy_pass http://localhost:300;
}

location / {
    root barp;

    set $page 'landing.html';

    if ($http_cookie ~ 'sid'){
        set $page '/index.html';
    }

    try_files $page =500;
}

I thought that all urls, except /api* and /auth*, would fit under the last section, and either landing.html or index.html would be returned, but when I make a request, for example, to /search, I get a 404 error. How can I make all urls except /api* and /auth* masks be processed by the last section?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
whiteX, 2014-10-17
@uSide

I will suggest so.
This configuration works for me

location ~ ^/auth(.*)$ {
    proxy_pass http://localhost:300;
}
location ~^ /api(.*)$ {
    if ($http_cookie ~ 'sid'){
        proxy_pass http://localhost:300;
        break;
    }

    return 403;
}

P
Puma Thailand, 2014-10-17
@opium

they come there and look at the nginx logs and everything will become clear to you

A
Antony Ryabov, 2014-10-17
@tonymadbrain

Also, don't use regular expressions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question