schemacs
schemacs

Reputation: 2891

nginx location directive not working as expected

The following configuration will rewrite /admin while proxy_pass /core, I can't figure out the reason. Any hint on this? Similar case like this Nginx: location regex for multiple paths with backend .

location / {
    if (!-e $request_filename) {
        rewrite ^(.*)$ /\#$1 break;
    }
}

location ~ ^/(admin|core)/ {
    proxy_pass http://127.0.0.1:8080/$1;
}

Upvotes: 0

Views: 820

Answers (2)

Cole Tierney
Cole Tierney

Reputation: 10304

Using try_files will simplify things.

location /
    try_files $uri $uri/ =404;
}

location ~ ^/(?:admin|core)/ {
    proxy_pass http://127.0.0.1:8080;
}

Upvotes: 1

Aleksey Deryagin
Aleksey Deryagin

Reputation: 2675

Try this variant:

location ~ ^/(admin|core)(.*)$ {
    proxy_pass http://127.0.0.1:8080/$1;
}

Upvotes: 0

Related Questions