User Tools

Site Tools


wiki:nginx_troubleshooting

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
wiki:nginx_troubleshooting [2023/09/07 13:28] – add Location matching when serving content antisawiki:nginx_troubleshooting [2023/10/03 11:18] (current) – [Location matching when serving content] add help box antisa
Line 30: Line 30:
   * it could be that the //server_name// is not defined or there's a typo   * it could be that the //server_name// is not defined or there's a typo
   * pay attention to http vs. https and redirects; if you get redirected from http to https and this is not what you want, redirect could be done by some proxied app (for example wordpress might do this via its WP_HOME and WP_SITEURL variables) and then the request will happen to 443 port on which nginx will serve the first vhost that is listening on this port and the //server_name// matches, so if your b.example.com vhost does not listen on 443 as well you might get the configuration from some other vhost which does listen on 443 which will confuse you.   * pay attention to http vs. https and redirects; if you get redirected from http to https and this is not what you want, redirect could be done by some proxied app (for example wordpress might do this via its WP_HOME and WP_SITEURL variables) and then the request will happen to 443 port on which nginx will serve the first vhost that is listening on this port and the //server_name// matches, so if your b.example.com vhost does not listen on 443 as well you might get the configuration from some other vhost which does listen on 443 which will confuse you.
 +  * Also listen directive gives precedence to IP:PORT than to only PORT, so nginx might serve for example wrong certificates (i.e. self-signed ones) if there is a config like
 +
 +<code nginx>
 +listen 1.2.3.4:443 ssl;
 +server_name de_verticals_upstream;                                                                                                                                                                             
 +                                                                                                                                                                                                                   
 +ssl_certificate     /etc/ssl/server.crt;                                                                                                                                                             
 +...
 +</code>
 +and somewhere else you have
 +<code nginx>
 +...
 +listen 443 ssl;
 +...
 +</code>
  
 ===== Location matching when serving content ===== ===== Location matching when serving content =====
Line 63: Line 78:
  
 </code> </code>
 +
 +So modifier priority matching is as follows:
 +
 +  1. `=`       Exact match, terminate immediately
 +  2. `^~`      Longest-prefix-match (not regex!)
 +  3. `~`, `~*` Regular expression case sensitive/insensitive
 +  4. `/`       Longest-prefix-match
 +
 +<WRAP center round help 60%>
 +If you are using the grouping of URIs in parenthesis e.g.
 +
 +  location ^~ /(.well-known|pathA|otherslug)
 +  
 +This won't work. Use the `~*` modifier for that.
 +</WRAP>
  
 ==== Tested on ==== ==== Tested on ====
wiki/nginx_troubleshooting.1694086137.txt.gz · Last modified: 2023/09/07 13:28 by antisa

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki