
我已經在 ubuntu 21 機器上安裝了 nginx 和 jenkins。
使用此中的步驟將 nginx 設定為將 80 流量重新導向至 8080關聯
現在,能夠將流量從 80 重定向到 8080。更改了 /etc/default/jenkins 中的參數以新增行 --httpListenAddress=127.0.0.1
現在,詹金斯參數行如下所示。
JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT --httpListenAddress=127.0.0.1"
然後也重啟了機器,但仍然可以直接用8080連接埠存取。
請建議如何實現這一目標。
azureuser@jenkins:~$ ss -lnpt
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 511 0.0.0.0:80 0.0.0.0:*
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 4096 *:3000 *:*
LISTEN 0 50 *:8080 *:*
LISTEN 0 128 [::]:22 [::]:*
azureuser@jenkins:~$ ps auxw | grep jenkins
jenkins 6761 0.1 11.8 3036280 416756 ? Ssl Mar29 8:08 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/java/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
azureus+ 86025 0.0 0.0 8548 2356 pts/0 S+ 19:09 0:00 grep --color=auto jenkins
答案1
/etc/default/jenkins
由於某種原因,您的 Jenkins 命令列不包含設定的選項。
請仔細檢查是否JENKINS_ARGS
正確並包含該選項。也嘗試重新啟動詹金斯。
答案2
根據這答案,/etc/default/jenkins
檔案在最近的 Jenkins 版本中不再使用。您將需要更新 Jenkins systemd 服務才能實現您的目標:
/lib/systemd/system/jenkins.service
透過文字編輯器開啟。- 找到包含 Jenkins 監聽位址環境變數的行:
#Environment="JENKINS_LISTEN_ADDRESS="
- 刪除註解並使用本機 IP 更新變數值:
Environment="JENKINS_LISTEN_ADDRESS=127.0.0.1"
- 儲存檔案並重新載入 systemd 單元檔案:
systemctl daemon-reload
- 重新啟動詹金斯:
systemctl restart jenkins
詹金斯現在應該在本地主機上監聽:
$ netstat -plunt | grep 8080
tcp6 0 0 127.0.0.1:8080 :::* LISTEN 11661/java