Questions tagged [nginx-location]

Questions related to nginx location directive should use this tag.

1424 questions
262
votes
5 answers

How can I have same rule for two locations in NGINX config?

How can I have same rule for two locations in NGINX config? I have tried the following server { location /first/location/ | /second/location/ { .. .. } } but nginx reload threw this error: nginx: [emerg] invalid number of arguments in…
nothing_authentic
  • 2,927
  • 3
  • 17
  • 22
78
votes
1 answer

Guide on how to use regex in Nginx location block section?

Nginx regex location syntaxe Regex expressions can be used with Nginx location block section, this is implemented with the PCRE engine. What does exactly this feature support as it is not fully documented?
intika
  • 8,448
  • 5
  • 36
  • 55
58
votes
1 answer

Nginx location matches

What is the difference between: location = /abc {} and locaton ~ /abc {}
user650505
  • 3,791
  • 4
  • 17
  • 7
26
votes
6 answers

nginx location 404 not found

Here are my nginx configure files. On the default.conf, the first location is used to access /usr/share/nginx/html directory, it is ok while I access http://47.91.152.99. But when I add up a new location for directory /usr/share/nginx/public…
22
votes
3 answers

Docker Nginx Angular2/Angular routes

I have an Angular2/Angular app running inside a docker container and using nginx to serve it. So my app base = /myapp/. Everything works correctly when hitting the app using the base url i.e. www.server.com/myapp or www.server.com/myapp/ events { …
Steve Fitzsimons
  • 3,754
  • 7
  • 27
  • 66
18
votes
1 answer

How to control NGINX 'Location' directive matching order?

I'm trying to optimize my 'location' directives and cannot find a good way of determining if a specific location match is even attempted. Using echo inside the location block doesn't help here. The NGINX ngx_http_core_module documentation is…
leeoniya
  • 1,071
  • 1
  • 9
  • 25
14
votes
1 answer

Fallback NGINX location

I’m new to NGINX and I am migrating a server. I haven’t finished everything on the new server, so I want it to match to the new server, unless that resource or path doesn’t exist. If so, I want to send it to the old server. Is there way to do that?
dkimot
  • 2,239
  • 4
  • 17
  • 25
14
votes
1 answer

auth_basic within location block doesn't work when return is specified?

i thought this would work but for some reason it skips the auth_basic and always returns 200. Same happens if i swap 200 for a 301 redirect. If i comment out the return statement it works ok. Ideally i want just an /auth endpoint that once…
Flo Woo
  • 949
  • 1
  • 12
  • 26
13
votes
2 answers

How to exclude specific subdomains server_name in nginx configuration

I'm using wildcard in server_name. I want to redirect all subdomains of example.com (configured as *.example.com) to foo.com except xyz.example.com I have configuration as follows server { listen 80; server_name …
pgollangi
  • 848
  • 3
  • 13
  • 28
12
votes
2 answers

How nginx process =404 fallback in try_files

I have a example web server with only one index.html file in a www directory. I can setup a nginx with following configuration: location /subfolder { alias /data/www; try_files $uri $uri/ /index.html; } In browser I can see correct…
l2ysho
  • 2,542
  • 1
  • 20
  • 41
12
votes
1 answer

nginx location with and without trailing slash

I would like to create a location which catches both http://example.com and http://example.com/ and another location which catches everything else. The first one will serve static html and the other one is for the api and other stuff. I've tried…
Miquel
  • 8,339
  • 11
  • 59
  • 82
12
votes
2 answers

How to use Nginx Regexp in the location

The web project have static content into the some /content/img folder. The url rule is: /img/{some md5} but location in the folder: /content/img/{The first two digits}/ Example url: example.com/img/fe5afe0482195afff9390692a6cc23e1 location:…
Alexandre Kalendarev
  • 681
  • 2
  • 10
  • 24
11
votes
2 answers

NGINX: remove part of url permanantly

I have redesigned a website and changed the url formats too. Now i need to change the old url to new one. Here is my old url: http://www.example.com/forum/showPost/2556/Urgent-Respose The new url will…
Pulkit Sharma
  • 264
  • 1
  • 2
  • 18
11
votes
1 answer

nginx location tilde

What is the tilde (~) doing in an Nginx Location directive? ie: location ~* \.(png|gif|jpg)$ { [...configuration] }
Cory Robinson
  • 4,616
  • 4
  • 36
  • 53
10
votes
1 answer

Nginx location's regex, is escaping the forward slash needed?

Nginx uses the PCRE engine for evaluating regular expressions, the documentation state that / delimiter is not used so we don’t have to escape the forward slash / in an URI as we may do in a standard regex. An example of a valid nginx regex is…
intika
  • 8,448
  • 5
  • 36
  • 55
1
2 3
94 95