Jenkins Web UI: What is the default port and how to change it

Updated: February 3, 2024 By: Guest Contributor Post a comment

Introduction

When you begin working with Jenkins, one of the initial tasks is to navigate through its Web User Interface (UI). Whether you’re setting up a new Jenkins instance or configuring an existing one, understanding how to access and modify its default port is crucial for seamless integration and accessibility. In this tutorial, we will walk you through the default port settings for Jenkins and provide detailed instructions on how to change it, catering to both beginners and advanced users.

Understanding Jenkins Default Port

Jenkins, by default, runs on port 8080. This setting allows users to access the Jenkins Web UI by visiting http://localhost:8080 in the web browser. While this default setting works perfectly for most instances, there might be situations where the port 8080 is either already in use or you prefer to use Jenkins on a different port for security, compliance, or personal preference reasons.

How to Change the Default Port

Method 1: Changing the Port from the Command Line

To change the default Jenkins port from the command line, you can use the --httpPort parameter when you start Jenkins:

java -jar jenkins.war --httpPort=9090

This command will start Jenkins on port 9090. You can replace 9090 with any port number that suits your requirements.

Method 2: Configuring the Port in the Jenkins Configuration File

If you prefer not to specify the port each time you start Jenkins, you can configure it permanently in the Jenkins configuration file. This process varies depending on your OS.

On Linux

sudo nano /etc/default/jenkins

In the file, find the JENKINS_ARGS line and modify it to include the new port:

JENKINS_ARGS="--httpPort=9090"

On Windows

For Windows installations, the process involves editing the jenkins.xml file located in the Jenkins home directory. Find the <--httpPort> argument and modify it accordingly:

<arguments>... --httpPort=9090 ...</arguments>

Advanced Configuration

Using HTTPS

For a more secure setup, you might want to run Jenkins on HTTPS instead of HTTP. You can accomplish this by using the --httpsPort and --httpsKeyStore parameters along with their respective configuration values:

java -jar jenkins.war --httpsPort=8443 --httpsKeyStore=/path/to/keystore --httpsKeyStorePassword=mypassword

This setup requires a valid SSL certificate. Ensure your keystore path and password are correctly specified.

Configuring a Reverse Proxy

In more complex setups, especially in corporate environments, Jenkins might be accessed through a reverse proxy. In this case, configuring Jenkins to run on a non-standard port while the proxy handles the standard HTTP or HTTPS ports can be beneficial.

This involves configuring the proxy server (e.g., Nginx or Apache) to forward requests to Jenkins. Here are example configurations for Nginx:

server {
  listen 80;
  server_name jenkins.example.com;

  location / {
    proxy_pass http://localhost:9090;
    include /etc/nginx/proxy_params;
  }
}

And for Apache:

<VirtualHost *:80>
  ServerName jenkins.example.com
  ProxyPass / http://localhost:9090/
  ProxyPassReverse / http://localhost:9090/
</VirtualHost>

With these configurations, users can access Jenkins through the proxy server’s domain, which redirects them to the Jenkins instance running on the specified non-standard port.

Conclusion

Customizing the Jenkins port is a fundamental task that can adapt the tool to fit your infrastructure’s specific needs, whether due to security policies, port conflicts, or personal preference. This tutorial covered essential to advanced configurations, ensuring you have the knowledge to modify the Jenkins port as required for your setup.