I'm running Ubuntu 11.10 and have run sudo apt-get install jenkins
to install Jenkins on this system.
I've seen some tutorials on how to setup a reverse proxy (Apache, Nginx, etc), however this is a VM dedicated for just jenkins and I'd like keep it as lean as possible while having jenkins running on port 80.
I've found the upstart config in /etc/init/jenkins.conf
and modified the port to 80 env HTTP_PORT=80
When I start jenkins via service jenkins start
, ps
reveals that it runs for a few seconds then terminates.
Is this because jenkins is running as the jenkins
user on a privileged port? If so, how do I fix this? Any other ideas a welcome.
Here is the upstart config:
description "jenkins: Jenkins Continuous Integration Server"
author "James Page <james.page@ubuntu.com>"
start on (local-filesystems and net-device-up IFACE!=lo)
stop on runlevel [!2345]
env USER="jenkins"
env GROUP="jenkins"
env JENKINS_LOG="/var/log/jenkins"
env JENKINS_ROOT="/usr/share/jenkins"
env JENKINS_HOME="/var/lib/jenkins"
env JENKINS_RUN="/var/run/jenkins"
env HTTP_PORT=80
env AJP_PORT=-1
env JAVA_OPTS=""
env JAVA_HOME="/usr/lib/jvm/default-java"
limit nofile 8192 8192
pre-start script
test -f $JENKINS_ROOT/jenkins.war || { stop ; exit 0; }
$JENKINS_ROOT/bin/maintain-plugins.sh
mkdir $JENKINS_RUN > /dev/null 2>&1 || true
chown -R $USER:$GROUP $JENKINS_RUN || true
end script
script
JENKINS_ARGS="--webroot=$JENKINS_RUN/war --httpPort=$HTTP_PORT --ajp13Port=$AJP_PORT"
exec daemon --name=jenkins --inherit --output=$JENKINS_LOG/jenkins.log --user=$USER \
-- $JAVA_HOME/bin/java $JAVA_OPTS -jar $JENKINS_ROOT/jenkins.war $JENKINS_ARGS \
--preferredClassLoader=java.net.URLClassLoader
end script
Another solution is to simply use iptables to reroute incoming traffic from 80 to 8080. The rules would look like:
Reformatted as an iptables.rules file:
The advantage of a iptable.rules file is the rules can persist after reboots. Just make sure to integrate any other current iptable rules into the same file!
On Redhat/CentOS this file can go in
/etc/sysconfig/iptables
.On Debian/Ubuntu systems they can be saved in
/etc/iptables/rules.v4
by using theiptables-persistent
package. Or the iptable.rules can be called by modifying/etc/network/interfaces
or hooking intoif-up
/if-down
scripts. The Ubuntu Community wiki has a great page explaining these methods.As is usually the case with networking, there's a lot of different ways to accomplish the same result. Use what works best for you!
I had the same problem and I found the best solution to it using iptables.
By default Jenkins runs on ports 8080 or 8443. And HTTP/HTTPS servers run on ports 80 and 443.
But this is these are the special ports and the process using them must be owned by root.
But running Jenkins as root is not the best solution(it should be run as its own user) and so does to run Jenkins with a web server such as Apache, and let it proxy requests to Jenkins
The best solution is to use iptables on Linux to forward traffic.
1) Use this command to list the current iptables configuration:
$ iptables -L -n
2) If you don't see above entries, then you need to run below commands:
3) Now re-run the
$ iptables -L -n
command and verify that you are seeing 1st step o/p.4) The final step is to run the below commands to forward port 80 traffic to 8080, and port 443 traffic to 8443(if you are using HTTPS).
5) Now your URL should stay on port 80
You can find the more details here.
Since I used docker. You can use it to run jenkins on port 80, hereafter a snippet of my script:
In Ubuntu 16.04, this wiki explains how to do it.
sudo nano /etc/rc.local
Then add the following just before the exit 0
Now reboot or run
sudo /etc/rc.local
to enable port forwardingchanging /etc/default/jenkins doesn't work on my setup ubunutu 16.-4 Jenkins 2.89.4 and the solution to use iptable routes 80 to 8080 whis the opposite of the required result of running jenkins on 80
the firewalld way to forward port 8080 to 80: