1

I am trying to make a site only accessible from within the local network and people from the external network will get a static page saying some other message.

This is what I am trying to do but it does not seem to work. Where have I gone wrong?

         if ($remote_addr != 192.168.1.0/24) {
                   rewrite ^/* /covid19 last;
         }
0

The $remote_addr is a single IP address (e.g. 192.168.1.123) so it will not directly compare with the string 192.168.1.0/24.

If you are comparing an IP address to a /24 block, you can use a regular expression that only checks the first three numbers.

For example:

if ($remote_addr !~ "^192\.168\.1\.") { ... }

See this document for details, and this caution on the use of if.

|improve this answer|||||
  • Thank you very much for the solution. It works and has helped me very much. Thank you again for helping me out when I was stuck. I do appreciate it very much. – P.V.Anthony Mar 26 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.