restrict access to the admin url by ip in django with nginx and gunicorn

后端 未结 1 939
醉话见心
醉话见心 2021-02-06 12:32

I am trying to restrict access to the admin section of my django app by using simple host-based access control in nginx. Unfortunately nginx does not seem to abide by the confi

1条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-06 13:09

    I found a solution to this problem by replacing the /admin/ location with the following:

    location ^~ /admin/ { # restrict access to admin section
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    
        allow 192.168.0.1;
        deny all;
    }
    

    I hope this will save someone some long searches on the internet. I would appreciate answers offering a better solution.

    0 讨论(0)
提交回复
热议问题