天天看點

Nginx使用http auth basic認證保護背景admin

需要對背景位址admin進行保護,

可以使用http auth basic,既友善又簡單,

1、首先要利用用apache 的 htpasswd 可以生成密碼檔案

隻好先安裝apache了

解壓之後

./configure --prefix=/home/app/httpd-2.0.63

make && make install

建立使用者和賬号:

/home/app/httpd-2.0.63/bin/htpasswd -c -d /home/nginx/conf/pass_file  username

然後需要輸入要密碼

再次确認資料即可生效了。

2、配置nginx

        location ~ /admin(/.*) 

        { 

                auth_basic "Restricted"; 

                auth_basic_user_file pass_file;

                #我的後端設定 proxy到resin,與認證無關 

                proxy_set_header Host "gz.schedule.163.com"; 

        }

這樣子,所有通路admin開頭的,都需要進行簡單的認證,解決燃眉之急!

注意 nginx 0.6.7 開始,auth_basic_user_file 的相對目錄是 nginx_home/conf,以前版本的相對目錄是 nginx_home。

重新開機:

/home/nginx/sbin/nginx –s reload

作者使用的nginx是:

/home/nginx/sbin/nginx –V

nginx version: nginx/0.8.53 

built by gcc 4.3.2 (Debian 4.3.2-1.1) 

configure arguments: --add-module=../ngx_cache_purge-1.1 --prefix=/home/app/nginx-0.8.53 --with-http_stub_status_module --with-pcre=../pcre-8.10

本文轉自jooben 51CTO部落格,原文連結:http://blog.51cto.com/jooben/429977

繼續閱讀