How to restrict access to the admin panel for external IP?

  • 0
    Question on the subject.

    I tried it like this:
    location ^~ /admin/ {
                    proxy_pass http://localhost:8000/;
                    proxy_set_header Host $http_host;
                    proxy_set_header X-Real-IP $remote_addr;
                    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
                    deny all;
                    allow 192.168.111.0/24;
                    allow 172.16.0.0/24;
    
            }


    But because of this, he constantly redirects to the main page of the site
    Django Sawyer Sanchez, Aug 15, 2020

  • 3 Answers
  • 0
    But because of this he constantly redirects to the main page of the site


    Maybe this will help? :) (attention to the trailing slash)
    proxy_pass http: // localhost: 8000;


    If deny all does not work, then either the request does not get to the location or there is 1 more reverse proxy ahead and the reception of the real address through headers is not configured (real_ip_header / set_real_ip_from).
    Arianna Wu

  • 0
    location ^~ /admin/ {
    proxy_pass http://localhost:8000/;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

    allow 192.168.111.0/24;
    allow 172.16.0.0/24;
    deny all;

    }



    Alternatively, try it.
    Anastasia Best

  • 0

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!