location block, redirect all but specific domain with any subdomain and any path
February 19, 2020 08:24AM
I am trying to do a redirect using location regex.I want everything to be redirected to 404 exept from the examplesite.com with every possible path and subdomain.examplesite.com should be redirected to my server.

examplesite.com redirect
https://m.examplesite.com redirect
www.examplesite.com/something redirect
everything else redirect to 404

This is my config:

location ~ ^(?!(.?)examplesite.com/?(.*)) {
return 404;

location / {
return 302 $scheme://; #this is a local web server

which must be wrong because it redirects every examplesite.com i tried to 404.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 70
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