2015-07-13 31 views
0

我想爲nginx的一種複雜的配置:nginx的訪問控制:一些允許自由,有的用密碼,或拒絕

  • 基本上所有來自Internet的訪問被拒絕(= deny all;
  • 網絡段應該被允許自由地訪問(= allow 10.0.1.0/24;
  • 另一個網絡段應該被允許訪問,與基本認證(= satisfy all; deny all; allow 10.0.2.0/24;

我想寫如下的配置文件,但當然它有一個錯誤,因爲satisfy只能出現一次。

location/{ 
    satisfy any; 
    allow 10.0.1.0/24; # allowed to access freely 
    deny all; 
    satisfy all; ### ERROR 
    allow 10.0.2.0/24; # allowed to access, with basic auth 
    auth_basic   "closed site"; 
    auth_basic_user_file "closed.htpasswd"; 
    # proxy to somewhere 
    http://localhost:10081; 
} 

我怎樣才能達到這一要求?

感謝,

回答

0

自答案(部分)

我可以接受修改server指令配置對於這種情況,所以下面的配置如下工作

server { 
    listen 80; 
    # server directive allows only these two networks 
    allow 10.0.1.0/24; 
    allow 10.0.2.0/24; 
    deny all; 
    location/{ 
     satisfy any; 
     # here comes the two networks above, so I can rely on "satisfy any" 
     allow 10.0.1.0/24; 
     deny all; 
     auth_basic   "closed site"; 
     auth_basic_user_file "closed.htpasswd"; 
     proxy_pass http://localhost:10081; 
    } 
} 

我希望有更多的直截了當的方式。

相關問題