<iframe id="aswift_0" style="margin: 0px; padding: 0px; border-width: 0px; outline: 0px; font-style: inherit; font-family: inherit; vertical-align: baseline; left: 0px; position: absolute; top: 0px;" name="aswift_0" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" width="468" height="60"></iframe>
一直在Apache下使用HTTP basic auth(.htpasswd)来保护网站的某些目录的访问,现在VPS上换成了Nginx同样需要保护一下。
Nginx下的配置也挺方便的,我们可以沿用由Apache的htpasswd模块生成的.htpasswd文件作为密码文件。注意,nginx 的 http auth basic 的密码是用 crypt(3) 加密的,而apache是md5加密。所以生成时:
1 |
/usr/local/apache2/bin/htpasswd -c -d pass_file user_name |
2 |
#回车输入密码,-c 表示生成文件,-d 是以 crypt 加密。 |
对于lnmp用户,一般不安装apache了,文末老N会告诉你个生成方法。
我们将这个htpasswd文件放到nginx/conf下,记得chmod 400 htpasswd来保护一下。
然后修改nginx.conf:
02 |
server_name d8.neolee.com;
|
03 |
root / var /www/d8.neolee.com;
|
04 |
include /etc/nginx/fastcgi_php;
|
06 |
auth_basic "Password please" ;
|
07 |
auth_basic_user_file /usr/local/nginx/conf/htpasswd;
|
09 |
if (!-e $request_filename ) {
|
10 |
rewrite ^(.*)$ /index.php last;
|
加入了
1 |
auth_basic "Password please" ;
|
2 |
auth_basic_user_file /usr/local/nginx/conf/htpasswd; |
重启nginx即可。
给了例子看看,请访问http://d8.neolee.com 用户名neo 密码123
========
最后我们说下怎么在nginx下生成htpasswd
下载这个python文件:http://trac.edgewall.org/export/10770/trunk/contrib/htpasswd.py (nginx wiki里推荐的)
运行示例
2 |
./htpasswd.py -c -b htpasswd username password |
分享到:
相关推荐
nginx的basic auth配置由ngx_http_auth_basic_module模块提供,对HTTP Basic Authentication协议进行了支持,用户可通过该配置设置用户名和密码对web站点进行简单的访问控制。 basic auth配置示例: location / { ...
内容概要:通过nginx配置实现控制不同的用户可以访问不同的资源或者web ...②Basic Auth相关知识。 阅读建议:改资源基于Linux-CentOS7系统操作,需要有一定的Linux命令操作基础和nginx安装和配置能力。
NULL 博文链接:https://phl.iteye.com/blog/2251771
从公共下载 : docker pull igortimoshenko/docker-nginx-basic-auth (或者,您可以从Dockerfile构建映像:docker docker build -t="igortimoshenko/docker-nginx-basic-auth" github....
使用方式:./htpasswd.py -c -b 生成文件名 用户名 密码,需要修改为可执行权限,chmod 777 htpasswd.py
有时候我们通过nginx搭建了一台文件服务器, 一般来讲是公开的, 但我们又希望该服务器不让他人看到, 有人可能会搭建一个登录系统, 但是太麻烦, 也没太大必要, 比较简单的做法是配置Basic Auth登录认证 1. 确定你安装...
docker run -d -p 80:80 --link web:web --name auth beevelop/nginx-basic-auth 尝试使用用户名foo和password bar访问和登录。 先进的 docker run -d \ -e HTPASSWD= ' foo:$apr1$odHl5EJN$KbxMfo86Qdve2FH4owePn...
3.5 Nginx的自动列目录配置 3.6 Nginx的浏览器本地缓存设置 第4章 Nginx与PHP( FastCGI) 的安装、 配置与优化 4.1 获取相关开源程序 4.2 安装PHP 5.2.10( FastCGI模式) 4.3 安装Nginx 0.8.15 4.4 配置开机自动...
.3.5 Nginx的自动列目录配置 3.6 Nginx的浏览器本地缓存设置 第4章 Nginx与PHP(FastCGI)的安装、配置与优化 4.1 获取相关开源程序 4.2 安装PHP 5.2.10(FastCGI模式) 4.3 安装Nginx 0.8.15 4.4 配置开机...
.3.5 Nginx的自动列目录配置 3.6 Nginx的浏览器本地缓存设置 第4章 Nginx与PHP(FastCGI)的安装、配置与优化 4.1 获取相关开源程序 4.2 安装PHP 5.2.10(FastCGI模式) 4.3 安装Nginx 0.8.15 4.4 配置开机自动启动...
一个轻量级的身份验证服务后端,旨在与nginx的auth_request一起使用。 特征 auth_request处理程序, 验证页面, 本地用户数据库。 用法 基本的 克隆此仓库。 通过pip install .安装此软件包pip install . (建议...
现在我们所使用的包括社交网络API等开放平台授权获得用户的用户名和密码一般有两种认证方式,一种是Basic Auth,一种是OAuth,这里我们就来看一下Nginx上配置Basic Authorization登录认服务证的教程
、limit_conn_module、ngx_http_limit_req_module、ngx_http_access_module、ngx_http_auth_basic_module、ngx_http_fastcgi_module、ngx_http_gzip_module、ngx_http_proxy_module、ngx_http_upstream_module、ngx_...
nginx用户认证配置( Basic HTTP ...默认情况下nginx已经安装了ngx_http_auth_basic_module模块,如果不需要这个模块,可以加上 –without-http_auth_basic_module 。 nginx basic auth指令 语法: auth_bas
Nginx提供HTTP的Basic Auth功能,配置了Basic Auth之后,需要输入正确的用户名和密码之后才能正确的访问网站。 我们使用htpasswd来生成密码信息,首先要安装httpd-tools,在httpd-tools中包含了htpasswd命令。 yum ...
Nginx保护目录的配置如下,目录密码保护文件是 /usr/local/nginx/htpasswd location ~ /admin { #admin为要保护的目录名称,location 的意思就是保护从网页根目录算起的admin 目录 auth_basic ”PLEASE LOGIN”; #...
先决条件: Nginx的nginx模块: 当前不包含)这个怎么运作: auth_request用于对另一台服务器进行身份验证(该服务器本身将auth_basic用于演示) 为auth_request设置了必要的标头(用户名,密码),并从加密的cookie...
Nginx是由1994年毕业于俄罗斯国⽴莫斯科鲍曼科技⼤学的同学...⽀持FastCGI/SSL/Virtual Host/URLRwrite/Gzip/HTTP Basic Auth/http或者TCP的负载均衡(1.9版本以上且开启stream模块)等功能,并且⽀持第三⽅的功能扩展。