You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(from Understanding Nginx Server and Location Block Selection Algorithms - https://goo.gl/YyzshP)
*[Alphabetical index of directives](http://nginx.org/en/docs/dirindex.html)
*[Alphabetical index of variables](http://nginx.org/en/docs/varindex.html)
*[Documentation](http://nginx.org/en/docs/)
```
server {
location {
}
}
```
## Blocks: server
Priority
1. listen
2. server_name
### Directives: listen
The *listen* directive can be set to:
* An IP address/port combo.
* A lone IP address which will then listen on the default port 80.
* A lone port which will listen to every interface on that port.
* The path to a Unix socket.
When "incomplete" listen directives
* A block with no listen directive uses the value 0.0.0.0:80.
* A block set to an IP address 111.111.111.111 with no port becomes 111.111.111.111:80
* A block set to port 8888 with no IP address becomes 0.0.0.0:8888
#### Options: default_server
```json
server {
listen 80 default_server;
server_name example.net www.example.net;
...
}
```
### Directives: server_name
Nginx evaluates these by using the following formula:
* Nginx will first try to find a server block with a server_name that matches the value in the "Host" header of the request exactly.
* Find a server block with a server_name that matches using a leading wildcard (indicated by a * at the beginning of the name in the config).
* If no match is found using a leading wildcard, Nginx then looks for a server block with a server_name that matches using a trailing wildcard (indicated by a server name ending with a * in the config).
* If no match is found using a trailing wildcard, Nginx then evaluates server blocks that define the server_name using regular expressions (indicated by a ~ before the name).
* If no regular expression match is found, Nginx then selects the default server block for that IP address and port.
* (none): The location is interpreted as a prefix match. This means that the location given will be matched against the beginning of the request URI to determine a match.
* =: This block will be considered a match if the request URI exactly matches the location given.
*~: This location will be interpreted as a **case-sensitive** regular expression match.
*~*: The location block will be interpreted as a **case-insensitive** regular expression match.
* ^~: If this block is selected as the best non-regular expression match, regular expression matching will not take place.
If a request is made for /blahblah, the first location will initially get the request. It will try to find a file called blahblah in /var/www/main directory. If it cannot find one, it will follow up by searching for a file called blahblah.html.
### Directives: rewrite
```
rewrite ^/rewriteme/(.*)$ /$1 last;
```
A request for /rewriteme/hello will be handled initially by the first location block. It will be rewritten to /hello and a location will be searched.