使用Nginx http auth保护Jenkins(回调URL除外)

我在服务器上安装了jenkins,并希望通过nginx http auth保护它,以便请求:

http://my_domain.com:8080

http://ci.my_domain.com

除以下位置外,将受到保护:

http://ci.my_domain.com/job/my_job/build

需要触发构建。我对nginx有点陌生,所以我坚持使用nginx config。

upstream jenkins {

server 127.0.0.1:8080;

}

server {

listen x.x.x.x:8080;

server_name *.*;

location '/' {

proxy_pass http://jenkins;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header Host $http_host;

proxy_redirect off;

auth_basic "Restricted";

auth_basic_user_file /path/.htpasswd;

}

}

我尝试了类似上面的配置的smth,但是当我访问时http://my_domain.com:8080没有http auth。

回答:

最后,我弄清楚了如何解决这个问题。首先,我们需要在“管理Jenkins”页面上取消选中“启用安全性”选项。停用安全功能后,我们可以通过诸如这样的请求触发我们的工作http://ci.your_domain.com/job/job_name/build

如果要添加令牌来触发URL,我们需要启用安全性,请选择“基于项目的矩阵授权策略”,并将“管理”权限授予匿名用户。在项目的“配置”页面中之后,将出现“远程生成触发器”选项,您可以在其中指定令牌,以便您的请求看起来像JENKINS_URL/job/onru/build?token=TOKEN_NAME

因此,在禁用安全性的情况下,我们需要使用nginx http_auth

保护http://ci.your_domain.com,但网址除外/job/job_name/build'

当然,我们需要对外部请求隐藏8080端口。因为我的服务器在Ubuntu上,所以我可以使用 防火墙:

iptables -A INPUT -p tcp --dport 8080 -s localhost -j ACCEPT

iptables -A INPUT -p tcp --dport 8080 -j DROP

但!在ubuntu(我不确定其他Linux操作系统)上,iptables在重启后会消失。因此,我们需要保存它们:

iptables-save

这还不是终点。使用此命令,我们只获得一个带有iptables的文件。在启动时,我们需要加载iptables,最简单的方法是使用“ uptables-

persistent”包:

sudo apt-get install iptables-persistent

iptables-save > /etc/iptables/rules

如果需要,请仔细查看iptables

https://help.ubuntu.com/community/IptablesHowTo#Saving_iptables,祝詹金斯好运!

在服务器的子域上运行jenkins就是一个很好的例子:https ://wiki.jenkins-

ci.org/display/JENKINS/Running+Hudson+behind+Nginx

以上是 使用Nginx http auth保护Jenkins(回调URL除外) 的全部内容, 来源链接: utcz.com/qa/407796.html

回到顶部