Welcome! Log In Create A New Profile

Advanced

Re: Nginx Reverse Proxy Lowercase URL and some exceptions to the URL

October 05, 2019 12:41PM
Dear David:

I am very grateful for your help! Below is the final configuration working optimally. I even included the proxy configuration parameters for the websocket connection to work.I noticed that the location =/ does not support OR so I had create two additional locations to catch paths without the end forward slash. Is there a limit in the number of location that a configuration file should have?

I do have some other additional configuration I want to do, but I will post another message with it.

Thank YOU again for being in this forum and helping everyone!

Regards,

Alex

# SERVER DEFINITIONS
##BETA EXAMPLE HTTP SERVER CONFIGURATION START
server {

listen 80;

server_name example.com;

## URL REWRITE FUNCTION THAT LOWERCASES ALL URIS
## START -- THIS IS INSIDE THE HTTP, BUT IT IS HERE FOR ILLUSTRATION PURPOSES

perl_set $my_uri_to_lowercase 'sub {
my $r = shift;
my $uri = $r->uri;
$uri = lc($uri);
return $uri;
}';
## URL REWRITE FUNCTION THAT LOWERCASES ALL URIS
## END





## LOCATION #1
## THIS LOCATION WILL PREVENT LOWERCASING IN ANY URI THAT BEGINS WITH /API/WHATEVER , /CONTENTASSET/WHATEVER, ETC.
## ~ MEANS IT IS A REGEX
## ~* MAKES IT CASEINSENSITIVE SO EITHER /api/ or /API/ will not be lowercased
## ^ MAKES IT MATCH WITH THE BEGINING OF THE "/" AND THE PATH WE DO NOT WANT TO LOWERCASE
## I ADDED THE proxy_pass as observation of David Francis on Nginx Forum
## IF URI MATCHES THIS LOCATION THEN IT WILL STOP SEARCHING FOR OTHER LOCATION MATCHES

location ~ ^/(api|contentAsset|categoriesServlet|DotAjaxDirector|html|dwr|dA|JsonTags)/ {
proxy_pass http://xxx.xx.xx.xxx:IIII;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
proxy_redirect off;

###
### ADD THIS FOR WEBSOCKET SUPPORT
###

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";

}


## LOCATION #2
## THIS LOCATION WILL CATCH THE NECESSARY STRINGS WITHOUT A FORWARD SLASH
## SO THAT THE BACKEND WORKS PROPERTY

location = /categoriesServlet {
proxy_pass http://xxx.xx.xx.xxx:IIII;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
proxy_redirect off;

###
### ADD THIS FOR WEBSOCKET SUPPORT
###

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";

}

##LOCATION #3
## HANDLES ONE PATH WITHOUT FOWARD SLASH
##

location = /JSONTags {
proxy_pass http://xxx.xx.xx.xxx:IIII;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
proxy_redirect off;

###
### ADD THIS FOR WEBSOCKET SUPPORT
###

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";

}


## LOCATION #4
## THIS LOCATION WILL LOWERCASE ANYTHING THAT HAS UPPCASE LETTERS
## EXCEPT THE PATHS STATED ON LOCATION #1
location ~ [A-Z] {

return 301 $scheme://$host$my_uri_to_lowercase;

proxy_pass http://xxx.xx.xx.xxx:IIII;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
proxy_redirect off;
}

## LOCATION #5
## THIS LOCATION IS THE DEFAULT LOCATION
location / {
proxy_pass http://xxx.xx.xx.xxx:IIII;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
proxy_redirect off;

}


}
##BETA EXAMPLE HTTP SERVER CONFIGURATION END
Subject Author Posted

Nginx Reverse Proxy Lowercase URL and some exceptions to the URL

Alex Med October 03, 2019 11:36AM

Re: Nginx Reverse Proxy Lowercase URL and some exceptions to the URL

Francis Daly October 03, 2019 11:56AM

Re: Nginx Reverse Proxy Lowercase URL and some exceptions to the URL

Alex Med October 03, 2019 12:21PM

Re: Nginx Reverse Proxy Lowercase URL and some exceptions to the URL

Alex Med October 03, 2019 01:03PM

Re: Nginx Reverse Proxy Lowercase URL and some exceptions to the URL

Francis Daly October 03, 2019 01:38PM

Re: Nginx Reverse Proxy Lowercase URL and some exceptions to the URL

Francis Daly October 03, 2019 03:06PM

Re: Nginx Reverse Proxy Lowercase URL and some exceptions to the URL

Alex Med October 04, 2019 03:36PM

Re: Nginx Reverse Proxy Lowercase URL and some exceptions to the URL

Francis Daly October 04, 2019 04:52PM

Re: Nginx Reverse Proxy Lowercase URL and some exceptions to the URL

Alex Med October 05, 2019 12:41PM

Re: Nginx Reverse Proxy Lowercase URL and some exceptions to the URL

Alex Med October 05, 2019 12:50PM

Re: Nginx Reverse Proxy Lowercase URL and some exceptions to the URL

Francis Daly October 06, 2019 07:16AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 86
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready