Created
April 19, 2019 22:20
-
-
Save glagola/708f7f53db26e3963c03c92ee546c579 to your computer and use it in GitHub Desktop.
Nginx config: remove repeat slashes
This file contains 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
# https://www.example.com -> https://example.com | |
# http://www.example.com -> http://example.com | |
# *://example.com////// -> *://example.com | |
# *://example.com//////asdfasdfasd///asdfasdf// -> ..(multiple redirects).. -> *://example.com/asdfasdfasd/asdfasdf | |
server { | |
server_name www.example.com; | |
return 301 $scheme://bitwide.com$request_uri; | |
} | |
server { | |
listen 80 default_server; # it is important to be default server or "merge_slashes off" wont work | |
merge_slashes off; | |
server_name example.com; | |
rewrite "^/{2,}$" $scheme://$server_name permanent; | |
rewrite "^/{2,}(.+)$" /$1 permanent; | |
rewrite "^(.+[^/])/{2,}$" $1 permanent; | |
rewrite ^(.*?)//+(.+)$ $1/$2 permanent; | |
location / { | |
proxy_pass http://localhost:3000; | |
proxy_set_header Host $host; | |
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
proxy_set_header X-Real-IP $remote_addr; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment