阻止Jenkins访问端口8080

阻止Jenkins访问端口8080,jenkins,reverse-proxy,Jenkins,Reverse Proxy,我在我的Ubuntu服务器上安装了一个简陋的jenkins,我只需使用sudo apt get install jenkins,就可以从指向我邮箱的所有域访问jenkins,只需在URL上添加:8080 我已经成功地将apache配置为代理jenkins,我可以从ci.mydomain.com访问它,但我无法确定如何防止jenkins在端口8080上被访问 iptables -A INPUT -p tcp --dport 8080 -s localhost -j ACCEPT iptables

我在我的Ubuntu服务器上安装了一个简陋的jenkins,我只需使用sudo apt get install jenkins,就可以从指向我邮箱的所有域访问jenkins,只需在URL上添加
:8080

我已经成功地将apache配置为代理jenkins,我可以从
ci.mydomain.com
访问它,但我无法确定如何防止jenkins在端口8080上被访问

iptables -A INPUT -p tcp --dport 8080 -s localhost -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j DROP
这是我的apache配置文件:

<VirtualHost xx.xx.xx.xx:80>
    ServerAdmin me@mydomain.com
    ServerName ci.mydomain.com

    ProxyPass         /  http://localhost:8080/
    ProxyPassReverse  /  http://localhost:8080/
    ProxyRequests     Off

    <Proxy http://localhost:8080/*>
        Order deny,allow
        Allow from all
    </Proxy>
</VirtualHost>

服务器管理员me@mydomain.com
ServerName ci.mydomain.com
ProxyPass/http://localhost:8080/
ProxyPassReverse/http://localhost:8080/
代理请求关闭
命令拒绝,允许
通融

我遵循了Ubuntu的说明,但它们似乎没有任何效果。

您可以使用iptables,因为它是Ubuntu,阻止所有非本地访问端口8080

iptables -A INPUT -p tcp --dport 8080 -s localhost -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j DROP
还有另一种解决方案(不需要IPtables):

  • 防止在端口8080的服务器外部访问jenkins:

    • 编辑文件/etc/default/jenkins
    • HTTP\u HOST=127.0.0.1
    • 最后更改行:

      • 发件人:
        JENKINS_ARGS=“--webroot=/var/cache/$NAME/war--httpPort=$HTTP_PORT”
      • 致:
        JENKINS_ARGS=“--webroot=/var/cache/$NAME/war--httpPort=$HTTP_PORT--httplistenadress=$HTTP_HOST”
    • 重新启动詹金斯号
      systemctl重启jenkins


您可以使用
iptables
阻止所有非本地访问端口8080,因为它是Ubuntu
iptables-A INPUT-t tcp--dport 8080-s localhost-j ACCEPT
iptables-A INPUT-t tcp--dport 8080-j DROP
@ionFish谢谢,它抱怨
--dport
选项无法识别,不过,也许可以将此作为一个答案添加进来?我得到的响应是
iptables v1.4.12:未知选项--dport“
我稍后会调查一下,我现在有重要的事情要做。是
-p
而不是
-t
导致dport问题,我已经更新了你的答案