将gitlab上的项目作为OpenGrok的输入,直接可以搜索全量代码。需要做基本的认证。
- 申请内部域名,支持域名访问
- 禁止IP+port+path的访问方式:使用nginx作为代理,利用iptables关闭端口的incoming流量
- 先直接在nginx上做基本的认证
这样可以确保本地的同步服务可以继续使用,但外部访问需要使用用户名+密码的方式。
关闭8080端口incoming流量
CentOS / RHEL : How to block incoming and outgoing ports using iptables
iptables -A INPUT -p tcp --destination-port 8080 -j DROP
关闭8080端口incoming流量
- 按照具体的规则删除:
iptables -D INPUT -p tcp --destination-port 8080 -j DROP
- 按行删除:
sudo iptables -L --line-numbers
列出行,执行sudo iptables -D INPUT 1
配置nginx认证
- 安装httpd-tools以生产密码文件
yum -y install httpd-tools
htpasswd -2 -c /usr/local/src/passwd.db username
为username生成密码,并使用SHA-256进行密码加密。保持在-c的参数文件中。
这个文件每行保持一组用户名密码信息。nginx的auth_basic_user_file
模块支持配置多个用户
可以使用htpasswd -h
查看其它参数
- 配置nginx
server {
listen 80;
server_name opengrok.domain.com;
auth_basic "not ready, only master can go"; #添加此配置
auth_basic_user_file /usr/local/src/passwd.db; #加载生成的密码文件
if ($host != "opengrok.domain.com") {
return 404;
}
location / {
proxy_pass http://localhost:8080/;
}
}
- 重启nginx即生效,
nginx -s reload
(需要root用户配置nginx服务,先执行nginx -t
进行验证test)
下一步再研究接入SSO的方式如何实现。
网友评论