前情提要:
flink服务的rest接口默认绑定在公网IP地址的8081端口, 访问无任何验证信息,可能存在安全隐患.
使用nginx的反向代理+basic auth 可以实现账号密码验证.
大致分2步骤: 生成账号密码文件 , 配置nginx代理.
机器环境信息:
[root@localhost nginx]# nginx -v
nginx version: nginx/1.16.1
[root@localhost nginx]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)
1.生成账号密码文件
示例账号admin 密码xxxx
htpasswd -bc /etc/nginx/conf.d/htpasswd.users admin xxxx
2.在nginx 配置文件http区域添加配置
server {
listen 8082 default_server;
server_name 120.221.32.157;
auth_basic "user pwd";
auth_basic_user_file /etc/nginx/conf.d/htpasswd.users;
location /
{
proxy_pass http://127.0.0.1:8081;
}
}
说明:
server {
listen 监听端口
server_name 地址
auth_basic web页面提示信息
auth_basic_user_file 密码文件
location /
{
proxy_pass 反向代理到本机需要加密的web页面地址
}
}
补充:
无htpasswd需要安装httpd ,yum安装如下,实际因机器环境不同可能依赖包不同
yum install httpd
Installing : apr-1.4.8-7.el7.x86_64 1/5
Installing : apr-util-1.5.2-6.el7.x86_64 2/5
Installing : httpd-tools-2.4.6-97.el7.centos.x86_64 3/5
Installing : mailcap-2.1.41-2.el7.noarch 4/5
Installing : httpd-2.4.6-97.el7.centos.x86_64
nginx yum安装
yum install nginx 实际可能因环境不同有所出入
Installing : centos-indexhtml-7-9.el7.centos.noarch 1/13
Installing : gperftools-libs-2.6.1-1.el7.x86_64 2/13
Installing : 1:nginx-filesystem-1.16.1-3.el7.noarch 3/13
Installing : 1:openssl11-libs-1.1.1g-1.el7.x86_64 4/13
Installing : libXpm-3.5.12-1.el7.x86_64 5/13
Installing : gd-2.0.35-27.el7_9.x86_64 6/13
Installing : 1:nginx-mod-http-perl-1.16.1-3.el7.x86_64 7/13
Installing : 1:nginx-mod-mail-1.16.1-3.el7.x86_64 8/13
Installing : 1:nginx-mod-http-xslt-filter-1.16.1-3.el7.x86_64 9/13
Installing : 1:nginx-mod-stream-1.16.1-3.el7.x86_64 10/13
Installing : 1:nginx-1.16.1-3.el7.x86_64 11/13
Installing : 1:nginx-mod-http-image-filter-1.16.1-3.el7.x86_64 12/13
Installing : 1:nginx-all-modules-1.16.1-3.el7.noarch 13/13
参考文章: