如何使用nginx限制访问?

时间:2015-09-22 13:14:59

标签: django nginx

我有nginx配置:

location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    add_header X-Handled-By $upstream_addr;

    if (!-f $request_filename) {
        proxy_pass http://localhost:8000;
        break;
    }
}

我想限制访问location / custom_admin /到我的ip,但如果我添加:

location ~/custom_admin/(.*) {
    allow my_ip;
    deny all;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    add_header X-Handled-By $upstream_addr;

    if (!-f $request_filename) {
        proxy_pass http://localhost:8000;
        break;
    }
}

不工作。怎么做?

0 个答案:

没有答案
相关问题