如何将Jenkins的localhost:8080替换为自定义主机名XYZ.com
Fixing Jenkins Hostname (xyz.com) Access for Your Internal Team
Hey there! Let's get that Jenkins hostname sorted out—changing just the Jenkins Location setting often isn't enough, since there are a few key pieces to adjust for full internal access. Here's the complete step-by-step solution:
1. First, Let Jenkins Listen to All Network Interfaces
The root issue might be that your Jenkins instance is still only bound to localhost (127.0.0.1), which blocks access from other machines on your company network. Here's how to fix that:
For Linux (systemd-based setups):
- Open the Jenkins service config file with your preferred editor:
sudo nano /lib/systemd/system/jenkins.service - Add or modify the
JENKINS_LISTEN_ADDRESSenvironment variable to bind to all interfaces:Environment="JENKINS_LISTEN_ADDRESS=0.0.0.0" Environment="JENKINS_PORT=8080" - Save the file, then reload systemd and restart Jenkins:
sudo systemctl daemon-reload sudo systemctl restart jenkins
For Windows:
- Navigate to your Jenkins installation folder (usually
C:\Program Files\Jenkins) and openjenkins.xml. - In the
<arguments>section, add--httpListenAddress=0.0.0.0to the list. It should look something like:<arguments>-Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "%BASE%\jenkins.war" --httpListenAddress=0.0.0.0 --httpPort=8080</arguments> - Save the file, then restart the Jenkins service via Services.msc.
2. Double-Check the Jenkins Location URL (Your Initial Step)
- Head to Manage Jenkins > System Configuration > Jenkins Location
- Set the Jenkins URL to
http://xyz.com:8080(switch tohttps://if you have SSL configured later) - Hit Save at the bottom of the page.
3. Set Up Internal DNS Resolution
Your team’s machines need to know where xyz.com points. You have two options here:
- Internal DNS (Recommended): Ask your company’s IT team to add an A record mapping
xyz.comto your Jenkins server’s private internal IP (e.g.,192.168.1.100). This will work for everyone on the network automatically. - Temporary Hosts File Test: If you just want to validate before DNS is set up, add an entry to individual machines:
- Linux/macOS: Edit
/etc/hostsand add192.168.1.100 xyz.com - Windows: Edit
C:\Windows\System32\drivers\etc\hostsand add the same line.
- Linux/macOS: Edit
4. Optional: Remove the Port with a Reverse Proxy (Cleaner Access)
If you want your team to access Jenkins via just xyz.com (no :8080), set up a reverse proxy like Nginx or Apache. Here’s a quick Nginx example:
server { listen 80; server_name xyz.com; location / { proxy_pass http://localhost:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
- After setting up the proxy, update the Jenkins URL in Jenkins Location to
http://xyz.com(no port) - Restart Nginx and Jenkins to apply changes.
Troubleshooting Quick Checks
- Test reachability from another machine: Use
ping xyz.comto confirm DNS works, thentelnet xyz.com 8080to verify the port is open. - Firewall rules: Make sure your Jenkins server’s firewall allows incoming traffic on port 8080 (or port 80 if using a proxy) from your internal network.
- Clear browser cache: Old
localhostentries might be cached—do a hard refresh (Ctrl+Shift+R) to test.
内容的提问来源于stack exchange,提问作者Ananth Asamani
相关产品推荐
相关产品推荐

