[kwlug-disc] nginx config question
    Chris Frey 
    cdfrey at foursquare.net
       
    Thu Sep 28 12:32:43 EDT 2023
    
    
  
On Wed, Sep 27, 2023 at 11:25:52PM -0700, Ronald Barnes wrote:
> The server block that includes it might look like this:
> 
> server {
>   listen 80 ;
> 
>   server_name nextcloud.bclug.ca;
> 
>   ## Enable responses to /ping ... "pong", etc:
>   include ./sites-available/shared/ping.conf;
> 
>   return 301 https://$host$request_uri;
>   }
Nginx has a specific way of matching all location blocks.  Here's an article
I've found useful:
https://www.digitalocean.com/community/tutorials/nginx-location-directive
So based on that, I would suggest putting your 301 inside a location
block that comes last.  In this case it would be:
	location / {
		return 301 https://$host$request_uri;
	}
Your /ping would match ahead of this, because it is longer.  And any
regex-based locations would match ahead of /ping because they come
earlier in the search order.  And you still have = and ^~ to use if
you need to make sure one of the locations needs priority behaviour
over even the regex locations.
Hope that helps,
- Chris
    
    
More information about the kwlug-disc
mailing list