Welcome! Log In Create A New Profile

Advanced

Jenkins reverse proxy on single domain with multiple apps

Posted by [email protected] 
Hello,

I am trying to setup a reverse proxy on a single domain to host multiple
apps separated by URI, for example:
http://localhost/app1
http://localhost/app2
etc.

Right know having problems with reverse proxy jenkins which sends HTML page
in HTTP reply with relative paths eg. /static/abc/css/common.css

So far I have rewritten the content to the login screen as per below but I
want to know if there is any other way to rewrite this automatically:

location /jenkins {
proxy_pass http://jenkins:8080/;
sub_filter 'url=/login?from=%2F' 'url=/jenkins/login?from=%2F';
sub_filter "('/login?from=%2F')" "('/jenkins/login?from=%2F')";
sub_filter_once off;

}


Once I hit http://localhost/jenkins I am getting whole bunch of 404 because
of relative links as per the HTML response below


<!DOCTYPE html><html><head resURL="/static/a4190cd9" data-rooturl=""
data-resurl="/static/a4190cd9">


<title>Jenkins [Jenkins]</title><link rel="stylesheet"
href="/static/a4190cd9/css/layout-common.css" type="text/css" /><link
rel="stylesheet" href="/static/a4190cd9/css/style.css" type="text/css"
/><link rel="stylesheet" href="/static/a4190cd9/css/color.css"
type="text/css" /><link rel="stylesheet"
href="/static/a4190cd9/css/responsive-grid.css" type="text/css" /><link
rel="shortcut icon" href="/static/a4190cd9/favicon.ico"
type="image/vnd.microsoft.icon" /><link color="black" rel="mask-icon"
href="/images/mask-icon.svg" /><script>var isRunAsTest=false; var
rootURL=""; var resURL="/static/a4190cd9";</script><script
src="/static/a4190cd9/scripts/prototype.js"
type="text/javascript"></script><script
src="/static/a4190cd9/scripts/behavior.js"
type="text/javascript"></script><script
src='/adjuncts/a4190cd9/org/kohsuke/stapler/bind.js'
type='text/javascript'></script><script
src="/static/a4190cd9/scripts/yui/yahoo/yahoo-min.js"></script><script
src="/static/a4190cd9/scripts/yui/dom/dom-min.js"></script><script
src="/static/a4190cd9/scripts/yui/event/event-min.js"></script><script
src="/static/a4190cd9/scripts/yui/animation/animation-min.js"></script><script
src="/static/a4190cd9/scripts/yui/dragdrop/dragdrop-min.js"></script><script
src="/static/a4190cd9/scripts/yui/container/container-min.js"></script><script
src="/static/a4190cd9/scripts/yui/connection/connection-min.js"></script><script
src="/static/a4190cd9/scripts/yui/datasource/datasource-min.js"></script><script
src="/static/a4190cd9/scripts/yui/autocomplete/autocomplete-min.js"></script><script
src="/static/a4190cd9/scripts/yui/menu/menu-min.js"></script><script
src="/static/a4190cd9/scripts/yui/element/element-min.js"></script><script
src="/static/a4190cd9/scripts/yui/button/button-min.js"></script><script
src="/static/a4190cd9/scripts/yui/storage/storage-min.js"></script><script
src="/static/a4190cd9/scripts/hudson-behavior.js"
type="text/javascript"></script><script
src="/static/a4190cd9/scripts/sortable.js"
type="text/javascript"></script><script>crumb.init("Jenkins-Crumb",
"3842e2c3b39902ce834febe3772fe35c");</script><link rel="stylesheet"
href="/static/a4190cd9/scripts/yui/container/assets/container.css"
type="text/css" /><link rel="stylesheet"
href="/static/a4190cd9/scripts/yui/assets/skins/sam/skin.css"
type="text/css" /><link rel="stylesheet"
href="/static/a4190cd9/scripts/yui/container/assets/skins/sam/container.css"
type="text/css" /><link rel="stylesheet"
href="/static/a4190cd9/scripts/yui/button/assets/skins/sam/button.css"
type="text/css" /><link rel="stylesheet"
href="/static/a4190cd9/scripts/yui/menu/assets/skins/sam/menu.css"
type="text/css" /><meta name="ROBOTS" content="INDEX,NOFOLLOW" /><meta
name="viewport" content="width=device-width, initial-scale=1" /><script
src="/static/a4190cd9/jsbundles/page-init.js"
type="text/javascript"></script></head><body
data-model-type="jenkins.install.SetupWizard" id="jenkins"
class="yui-skin-sam full-screen jenkins-2.60.3" data-version="2.60.3"><div
id="page-body" class="clear"><div id="main-panel"><a
name="skip2content"></a><script
src="/static/a4190cd9/jsbundles/pluginSetupWizard.js"
type="text/javascript"></script><link rel="stylesheet"
href="/static/a4190cd9/jsbundles/pluginSetupWizard.css" type="text/css"
/><form method="POST" action="j_acegi_security_check"><input name="from"
type="hidden" value="/" /><div class="plugin-setup-wizard bootstrap-3"><div
class="modal fade in" style="display: block;"><div class="modal-dialog"><div
class="modal-content"><div class="modal-header"><h4
class="modal-title">Getting Started</h4></div><div class="modal-body"><i
class="water-mark icon-service"></i><div class="jumbotron welcome-panel
offline"><h1>Unlock Jenkins</h1><p>To ensure Jenkins is securely set up by
the administrator, a password has been written to the log (<small><a
href="https://jenkins.io/redirect/find-jenkins-logs"; target="_blank">not
sure where to find it?</a></small>) and this file on the server:
<p><small><code>/var/jenkins_home/secrets/initialAdminPassword</code></small></p></p><p>Please
copy the password from either location and paste it below.</p><div
class="form-group "><label class="control-label"
for="security-token">Administrator password</label><input name="j_username"
type="hidden" value="admin" /><input id="security-token"
class="form-control" type="password" name="j_password"
/></div></div></div><div class="modal-footer"><input type="submit"
class="btn btn-primary set-security-key" value="Continue"
/></div></div></div></div></div></form></div></div></body></html>

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,278748,278748#msg-278748

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Hi,

compare the output of

curl -ivvv http://jenkins:8080
curl -ivvv http://localhost/jenkins

then

curl -iLvvv http://jenkins:8080
curl -iLvvv http://localhost/jenkins

pay attention on the cookie headers.

java based applications usually may set session cookies and you should
handle them accordingly.

and it’s not clear (at least for me) why you’ve mentioned localhost/app1|2,
is that app1/app2 are different jenkins applications servers?


br,
Aziz.





> On 25 Feb 2018, at 11:08, kefiras@gmail.com <[email protected]> wrote:
>
> Hello,
>
> I am trying to setup a reverse proxy on a single domain to host multiple
> apps separated by URI, for example:
> http://localhost/app1
> http://localhost/app2
> etc.
>
> Right know having problems with reverse proxy jenkins which sends HTML page
> in HTTP reply with relative paths eg. /static/abc/css/common.css
>
> So far I have rewritten the content to the login screen as per below but I
> want to know if there is any other way to rewrite this automatically:
>
> location /jenkins {
> proxy_pass http://jenkins:8080/;
> sub_filter 'url=/login?from=%2F' 'url=/jenkins/login?from=%2F';
> sub_filter "('/login?from=%2F')" "('/jenkins/login?from=%2F')";
> sub_filter_once off;
>
> }
>
>
> Once I hit http://localhost/jenkins I am getting whole bunch of 404 because
> of relative links as per the HTML response below
>
>
> <!DOCTYPE html><html><head resURL="/static/a4190cd9" data-rooturl=""
> data-resurl="/static/a4190cd9">
>
>
> <title>Jenkins [Jenkins]</title><link rel="stylesheet"
> href="/static/a4190cd9/css/layout-common.css" type="text/css" /><link
> rel="stylesheet" href="/static/a4190cd9/css/style.css" type="text/css"
> /><link rel="stylesheet" href="/static/a4190cd9/css/color.css"
> type="text/css" /><link rel="stylesheet"
> href="/static/a4190cd9/css/responsive-grid.css" type="text/css" /><link
> rel="shortcut icon" href="/static/a4190cd9/favicon.ico"
> type="image/vnd.microsoft.icon" /><link color="black" rel="mask-icon"
> href="/images/mask-icon.svg" /><script>var isRunAsTest=false; var
> rootURL=""; var resURL="/static/a4190cd9";</script><script
> src="/static/a4190cd9/scripts/prototype.js"
> type="text/javascript"></script><script
> src="/static/a4190cd9/scripts/behavior.js"
> type="text/javascript"></script><script
> src='/adjuncts/a4190cd9/org/kohsuke/stapler/bind.js'
> type='text/javascript'></script><script
> src="/static/a4190cd9/scripts/yui/yahoo/yahoo-min.js"></script><script
> src="/static/a4190cd9/scripts/yui/dom/dom-min.js"></script><script
> src="/static/a4190cd9/scripts/yui/event/event-min.js"></script><script
> src="/static/a4190cd9/scripts/yui/animation/animation-min.js"></script><script
> src="/static/a4190cd9/scripts/yui/dragdrop/dragdrop-min.js"></script><script
> src="/static/a4190cd9/scripts/yui/container/container-min.js"></script><script
> src="/static/a4190cd9/scripts/yui/connection/connection-min.js"></script><script
> src="/static/a4190cd9/scripts/yui/datasource/datasource-min.js"></script><script
> src="/static/a4190cd9/scripts/yui/autocomplete/autocomplete-min.js"></script><script
> src="/static/a4190cd9/scripts/yui/menu/menu-min.js"></script><script
> src="/static/a4190cd9/scripts/yui/element/element-min.js"></script><script
> src="/static/a4190cd9/scripts/yui/button/button-min.js"></script><script
> src="/static/a4190cd9/scripts/yui/storage/storage-min.js"></script><script
> src="/static/a4190cd9/scripts/hudson-behavior.js"
> type="text/javascript"></script><script
> src="/static/a4190cd9/scripts/sortable.js"
> type="text/javascript"></script><script>crumb.init("Jenkins-Crumb",
> "3842e2c3b39902ce834febe3772fe35c");</script><link rel="stylesheet"
> href="/static/a4190cd9/scripts/yui/container/assets/container.css"
> type="text/css" /><link rel="stylesheet"
> href="/static/a4190cd9/scripts/yui/assets/skins/sam/skin.css"
> type="text/css" /><link rel="stylesheet"
> href="/static/a4190cd9/scripts/yui/container/assets/skins/sam/container.css"
> type="text/css" /><link rel="stylesheet"
> href="/static/a4190cd9/scripts/yui/button/assets/skins/sam/button.css"
> type="text/css" /><link rel="stylesheet"
> href="/static/a4190cd9/scripts/yui/menu/assets/skins/sam/menu.css"
> type="text/css" /><meta name="ROBOTS" content="INDEX,NOFOLLOW" /><meta
> name="viewport" content="width=device-width, initial-scale=1" /><script
> src="/static/a4190cd9/jsbundles/page-init.js"
> type="text/javascript"></script></head><body
> data-model-type="jenkins.install.SetupWizard" id="jenkins"
> class="yui-skin-sam full-screen jenkins-2.60.3" data-version="2.60.3"><div
> id="page-body" class="clear"><div id="main-panel"><a
> name="skip2content"></a><script
> src="/static/a4190cd9/jsbundles/pluginSetupWizard.js"
> type="text/javascript"></script><link rel="stylesheet"
> href="/static/a4190cd9/jsbundles/pluginSetupWizard.css" type="text/css"
> /><form method="POST" action="j_acegi_security_check"><input name="from"
> type="hidden" value="/" /><div class="plugin-setup-wizard bootstrap-3"><div
> class="modal fade in" style="display: block;"><div class="modal-dialog"><div
> class="modal-content"><div class="modal-header"><h4
> class="modal-title">Getting Started</h4></div><div class="modal-body"><i
> class="water-mark icon-service"></i><div class="jumbotron welcome-panel
> offline"><h1>Unlock Jenkins</h1><p>To ensure Jenkins is securely set up by
> the administrator, a password has been written to the log (<small><a
> href="https://jenkins.io/redirect/find-jenkins-logs"; target="_blank">not
> sure where to find it?</a></small>) and this file on the server:
> <p><small><code>/var/jenkins_home/secrets/initialAdminPassword</code></small></p></p><p>Please
> copy the password from either location and paste it below.</p><div
> class="form-group "><label class="control-label"
> for="security-token">Administrator password</label><input name="j_username"
> type="hidden" value="admin" /><input id="security-token"
> class="form-control" type="password" name="j_password"
> /></div></div></div><div class="modal-footer"><input type="submit"
> class="btn btn-primary set-security-key" value="Continue"
> /></div></div></div></div></div></form></div></div></body></html>
>
> Posted at Nginx Forum: https://forum.nginx.org/read.php?2,278748,278748#msg-278748
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Francis Daly
Re: Jenkins reverse proxy on single domain with multiple apps
February 25, 2018 04:40PM
On Sun, Feb 25, 2018 at 03:08:28AM -0500, kefiras@gmail.com wrote:

Hi there,

> I am trying to setup a reverse proxy on a single domain to host multiple
> apps separated by URI, for example:
> http://localhost/app1
> http://localhost/app2
> etc.

You will be much happier if your nginx/app1/ application believes that
it is installed at appserver/app1/, and not at appserver/.

> Right know having problems with reverse proxy jenkins which sends HTML page
> in HTTP reply with relative paths eg. /static/abc/css/common.css

For jenkins, use the jenkins "prefix" argument. For other apps, use
whatever their config/install options are.

> So far I have rewritten the content to the login screen as per below but I
> want to know if there is any other way to rewrite this automatically:

The easiest way is not to have to rewrite anything.

If jenkins is installed at /jenkins, then your nginx config will be
pretty much "proxy_pass http://jenkins:8080;";, unless you specifically
want nginx to handle some of the static files instead of jenkins.

Good luck with it,

f
--
Francis Daly francis@daoine.org
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
It was just an example, app1 or app2 may be any app, eg. zabbix or another
web server.
I have left the basic config for troubleshooting, my proxy pass is just as
per below:

location /jenkins {
proxy_pass http://jenkins:8080;
}

The very first GET is:

---
curl http://localhost:8123/jenkins


<html><head><meta http-equiv='refresh'
content='1;url=/login?from=%2Fjenkins'/><script>window.location.replace('/login?from=%2Fjenkins');</script></head><body
style='background-color:white; color:white;'>


Authentication required
<!--
You are authenticated as: anonymous
Groups that you are in:

Permission you need to have (but didn't): hudson.model.Hudson.Read
... which is implied by: hudson.security.Permission.GenericRead
... which is implied by: hudson.model.Hudson.Administer
-->

</body></html>
---

which tells the browser to go to http://localhost/login?from=%2Fjenkins but
it should be rewritten to http://localhost/jenkins/login?from=%2Fjenkins

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,278748,278769#msg-278769

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
The setup is a simple set of docker containers.

a 'localhost' is a docker container with nginx acting as a reverse proxy

it has defined /jenkins location to reverse proxy connection to jenkins
container which exposes the java app at port 8080 so:

location /jenkins {
proxy_pass http://jenkins:8080;
}

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,278748,278771#msg-278771

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
well, as I’ve said try checking headers first, as per the following doc:
https://wiki.jenkins.io/display/JENKINS/Jenkins+behind+an+NGinX+reverse+proxy

it can be much complicated than just proxy_pass’ing.

regarding sub_fillter,

try getting rid of one of the sub_filters, probably the second one:

proxy_pass http://jenkins:8080/;
sub_filter 'url=/login?from=%2F' 'url=/jenkins/login?from=%2F';
# sub_filter "('/login?from=%2F')" "('/jenkins/login?from=%2F')";
sub_filter_once off;

br,
Aziz.





> On 26 Feb 2018, at 18:03, kefiras@gmail.com <[email protected]> wrote:
>
> The setup is a simple set of docker containers.
>
> a 'localhost' is a docker container with nginx acting as a reverse proxy
>
> it has defined /jenkins location to reverse proxy connection to jenkins
> container which exposes the java app at port 8080 so:
>
> location /jenkins {
> proxy_pass http://jenkins:8080;
> }
>
> Posted at Nginx Forum: https://forum.nginx.org/read.php?2,278748,278771#msg-278771
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Thanks for help on this. I've fixed it by moving jenkins application to
/jenkins path on the application server. Now it's much simpler and it
appears it's working without hiccups

location /jenkins {
proxy_pass http://jenkins:8080;
proxy_redirect http://jenkins:8080/ http://nginx/;
}

Posted at Nginx Forum: https://forum.nginx.org/read.php?2,278748,278776#msg-278776

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Sorry, only registered users may post in this forum.

Click here to login