nginx用戶認證配置( Basic HTTP authentication)

ngx_http_auth_basic_module模塊實現讓訪問着,只有輸入正確的用戶密碼才容許訪問web內容。web上的一些內容不想被其餘人知道,可是又想讓部分人看到。nginx的http auth模塊以及Apache http auth都是很好的解決方案。php

默認狀況下nginx已經安裝了ngx_http_auth_basic_module模塊,若是不須要這個模塊,能夠加上 --without-http_auth_basic_module 。html

nginx basic auth指令

語法:     auth_basic string | off;
默認值:     auth_basic off;
配置段:     http, server, location, limit_exceptnginx

默認表示不開啓認證,後面若是跟上字符,這些字符會在彈窗中顯示。web

語法:     auth_basic_user_file file;
默認值:     —
配置段:     http, server, location, limit_exceptide

用戶密碼文件,文件內容相似以下:spa

 

nginx認證配置實例

 

備註:必定要注意auth_basic_user_file路徑,不然會不厭其煩的出現403。code

生成密碼server

能夠使用htpasswd,或者使用opensslhtm

帳號:ttlsa
密碼:123456blog

reload nginx

效果以下:

Apache

http_auth_basic_module

 

完成~

相關文章
相關標籤/搜索