今天运维同学检测到我们job管理后台访问时未经授权.安全起见需要增加下认证,但是重新搭建登录服务比较麻烦,所以想到利用nginx做认证.
1. 下载安装httpd-tools
yum install httpd-tools -y
2. 创建授权用户和密码
htpasswd -c -d /usr/local/nginx/conf/pass_file username
注意: pass_file的路径自定义,username是用户名,执行指令后,会让设置密码,账号和密码会保存在pass_file中
3. 配置nginx
server{
listen 30001 ;
server_name 服务名;
location /qrtz/query {
auth_basic "登录认证";
auth_basic_user_file /usr/local/nginx/conf/pass_file;
proxy_pass http://localhost:8080;
autoindex on;
autoindex_exact_size on;
autoindex_localtime on;
root /mnt/html/resource;
index index.html index.php;
}
}
使用location拦截需要增加认证的URL,
其中 auth_basic 和 auth_basic_user_file(配置的路径需要和上面生成的路径保持一致) 是认证的配置
4. 使用
在浏览器中访问30001端口号,不会被nginx拦截
访问具体/qrtz/query时会弹框要求输入用户名密码
这说明已经配置成功.