-1

I need to have access at the /jenkins path to the Jenkins server.

This is what I have now in my apache configuration:

ProxyPass /jenkins http://localhost:8080
ProxyPassReverse /jenkins http://localhost:8080

When I go to example.com/jenkins,
I get redirected to example.com/login?from=%2F,
instead of the expected exmaple.com/jenkins/login?from=%2F.

So is it possible with apache to make all the requests coming from my Jenkins server, be of the form example.com/jenkins/* instead of example.com/*?

P.S.: I know it would be a far better practice create a new server, named something like jenkins.example.com, but that's not an option for me at the moment.

DrKaoliN
  • 109
  • 1
  • 6
  • 1
    If you are being "redirected" then there would seem to be _something else_ doing that, not your proxy code? – MrWhite Sep 15 '17 at 09:57
  • Yes, the login request is the normal behavior expected from the Jenkins server, which goes to `/login?from=%2F`. But I want it to go to `/jenkins/login?from=%2F`. I'm not sure this is possible with apache. It could be that I cann only handle this from within the Jenkins server configuration. – DrKaoliN Sep 15 '17 at 10:08

2 Answers2

1

It looks like there is an option for configuring the Jenkins URL, inside Jenkins itself: Jenkins website root path.

Also, I have found the apache configuration documentation, in the Jenkins Wiki: Running Jenkins behind Apache.

EDIT:

I managed to achieve running the Jenkins server at http://example.com/jenkins like this:

  • on my local machine, by adding to the JENKINS_ARGS variable, the --prefix=/jenkins attribute, in /etc/default/jenkins file, and then restarting the Jenkins service. (soruce: this answer)
  • on my docker image, by adding --prefix=/jenkins at the end of the run command: docker run --name Jenkins -p 8080:8080 -p 50000:50000 jenkins --prefix=/jenkins

And here is my apache configuration entry for Jenkins:

ProxyPass        /jenkins http://localhost:8080/jenkins nocanon
ProxyPassReverse /jenkins http://localhost:8080/jenkins
ProxyRequests    Off
AllowEncodedSlashes NoDecode

Source: Running Jenkins behind Apache

DrKaoliN
  • 109
  • 1
  • 6
1

I tested such a setup on a dummy index.html.

ProxyPass "/jenkins" http://192.168.0.99
ProxyPassReverse "/jenkins" http://192.168.0.99

Like this it worked as expected, when I opened http://example.com/jenkins I got redirected to the index.html at http://192.168.0.99.

You should have a look in your htdocs root of jenkins. If there is a redirect like <meta http-equiv="refresh" content="0;URL=/login?from=%2F"> then it will redirect to example.com/login?from=%2F. If you change the redirect to relative path with leading ., it will redirect correctly:

<meta http-equiv="refresh" content="0;URL=./login?from=%2F">

Like this it would correctly redirect to example.com/jenkins/login?from=%2F

chloesoe
  • 335
  • 2
  • 17