Apache ProxyPass and errors - apache

I have two ProxyPass directives:
ProxyPass /client/ http://10.0.0.8:8080/client/
<Location /client/>
RequestHeader edit X-GWT-Module-Base ^(.*)/client/(.*)$ $1/client/$2
</Location>
ProxyPass / http://10.0.0.8:8080/client/
<Location />
RequestHeader edit X-GWT-Module-Base ^(.*)/(.*)$ $1/client/$2
</Location>
10.0.0.8 is running Glassfish on port 8080 and http://10.0.0.8:8080/client/ is URL to a GWT based application.
Both proxy's work OK ,except when it comes to an error on the Glassfish side.
If I go via /cllient/ proxy then I see the actual error that was produced on the Glassfish side. If I go via / proxy then I only see "Error 500 The call failed on the server, please see server log". I've tried setting ProxyErrorOverride Off, but it didn't help.
Why don't I see the error via / proxy?

https://groups.google.com/d/msg/google-web-toolkit/2P15JslejXg/dldFRN_pIeEJ
is the approach I'm using now and it works:
ProxyPass / http://10.0.0.8:8080/myGWTApp/
<Location />
RequestHeader edit X-GWT-Module-Base ^(http)://([^/]+)/(.*)$ $1://$2/myGWTApp/$3
</Location>

Related

ProxyRemote for Proxypass

I want to check my logic with you experts to check if it is correct.
What do I want to do?
Requests to Location search of suggest are send to Proxypass.
Proxypass connection is passed through the proxy with the Proxy Remote directive
Will that eventually work?
How can see if the proxy is being used?
ProxyRemote "https://website.com/query/search/" "http://proxy.com:8080"
ProxyRemote "https://website.com/query/suggest/" "http://proxy.com:8080"
<Location "/search">
RequestHeader set Auth-Key "test"
ProxyPass https://website.com/query/search/
</Location>
<Location "/suggest">
RequestHeader set Auth-Key "test"
ProxyPass https://website/query/suggest/
</Location>
Try adding LogLevel proxy:trace5 above the ProxyRemote entries.
Then check the apache2 logs (usually /var/log/apache2/access_log) for [proxy:...] entries: specifically look for [...] connecting https://website.com/[...] to website.com:443.
Don't forget to remove the LogLevel entry again, proxy:trace5 is pretty verbose.

Apache config api endpoint

I am running a vue js application as a v-host (app.test.com) on
http://app.test.com
The backend is a go application (which implements a webserver on its own) and is running on
http://localhost:8000
Is it possible to configure apache to redirect/proxy all request that go to http://app.test.com/api to http://localhost:8000 ?
Let's say i call http://app.test.com/api/endpoint1 from the vue application i'd like it to be proxied to http://localhost:8000/api/endpoint1.
I normaly have a dedicated dns for the api and using this config then in the v-host:
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://0.0.0.0:8000/
ProxyPassReverse / http://0.0.0.0:8000/
which works good.
But i can't figure out how to use this in a allready defined v-host.
Any hints/examples?
Many thanks
Sorry for this question. Managed to run this .. forgot to add the Proxy * directive to the config...
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /api/ http://0.0.0.0:8000/api/
ProxyPassReverse /api/ http://0.0.0.0:8000/api/
does it all, if someone Needs this

Jenkins - 403 Forbidden

I just installed Jenkins on an Ubuntu 16.04-server via:
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
echo "deb https://pkg.jenkins.io/debian-stable binary/" >> /etc/apt/sources.list
apt update
apt install jenkins
Afterwards I changed the port in /etc/default/jenkins to HTTP_PORT=8000 and added --httpPort=$HTTP_PORT --prefix=$PREFIX to the /etc/default/jenkins file and finally since I am running lots of stuff via apache already anyway I added a proxy there with:
ProxyErrorOverride On
ProxyPass "/jenkins" "http://127.0.0.1:8000/jenkins/"
ProxyPassReverse "/jenkins" "http://127.0.0.1/jenkins/"
But when I try to access https://MY_URL/jenkins I get an
Forbidden
You don't have permission to access /jenkins on this server.
But when I do curl localhost:8000 on the server I do seem to get the page. So it seems to be running on that port at least, I just cannot access it via the apache (Other Proxies like /gitlab do work though the same way).
Does anyone have an idea what might be the problem here?
Edit: When I disable ProxyErrorOverride On I finally see the page where I can enter the admin password but doing so redirects me to the same page again:
https://my_url/jenkins/login?from=%2Fjenkins%2F -> https://my_url/jenkins/login?from=%2Fjenkins%2F%2Fj_acegi_security_check.
So the current config for apache looks like this:
## Proxy Settings
ProxyRequests Off
ProxyPreserveHost On
AllowEncodedSlashes NoDecode
SetEnv proxy-nokeepalive 1
ProxyPass "/gitlab" "http://127.0.0.1:8001/gitlab/"
ProxyPassReverse "/gitlab" "http://127.0.0.1:8001/gitlab/"
ProxyPass "/jenkins" "http://127.0.0.1:8000/jenkins/" nocanon
ProxyPassReverse "/jenkins" "http://127.0.0.1:8000/jenkins/"
ProxyPassReverse "/jenkins" "http://my_url/jenkins/"
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"
Alright I finally found the error:
First ProxyErrorOverride On had to be removed and second I had to remove the trailing slash in the ProxyPass like this:
ProxyPass "/jenkins" "http://127.0.0.1:8000/jenkins" nocanon
ProxyPassReverse "/jenkins" "http://127.0.0.1:8000/jenkins"
ProxyPassReverse "/jenkins" "http://my_url/jenkins"
Interestingly gitlab did require it to work properly and jenkins does not work if the "/" are there.
Maybe, the firewall blocks Jenkins
For me, simply run this command to resolve this issue
/etc/init.d/iptables.sh stop

unable to login to jenkins(Unlock Jenkins)

I have installed Jenkins on Apache container and started it, but whenever I am trying to access it using the URL http://localhost:8080/jenkins/ I am being redirected to the URL http://localhost:8080/jenkins/login?from=%2Fjenkins%2F and then the pop up attached appears asking me for the password, I pasted the password from the file that is mentioned, to the textbox it is not getting disappeared, unsure what to do.
in my case the Jenkins was not unlocking with initial Admin password, then I thought of setting it up initially with Apache and then proceed with fixing the problem . The problem was in the number of slashes you put after ProxyPass and ProxyPassReverse entries.
Wrong entries
ProxyRequests Off
ProxyPreserveHost On
<Proxy http://localhost:8081/jenkins*>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /jenkins http://localhost:8081/jenkins/ nocanon
AllowEncodedSlashes NoDecode
ProxyPassReverse /jenkins http://localhost:8081/jenkins/
ProxyPassReverse /jenkins http://your.hostname.domain/jenkins/
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"
Correct one which worked.
ProxyRequests Off
ProxyPreserveHost On
<Proxy http://localhost:8081/jenkins*>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /jenkins http://localhost:8081/jenkins nocanon
AllowEncodedSlashes NoDecode
ProxyPassReverse /jenkins http://localhost:8081/jenkins
ProxyPassReverse /jenkins http://your.hostname.domain/jenkins
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"
Let me know your thoughts.
use instructions from https://github.com/geerlingguy/ansible-role-jenkins/issues/50#issuecomment-214935354 and check an update below regarding locking access for anonymous users - worked for me today.
Shamelessly stolen from the link above:
Create the file /var/lib/jenkins/jenkins.install.UpgradeWizard.state
with one line 2.0
Create the file
/var/lib/jenkins/init.groovy.d/basic-security.groovy with the
contents:
#!groovy
import jenkins.model.*
import hudson.security.*
def instance = Jenkins.getInstance()
println "--> creating local user 'admin'"
def hudsonRealm = new HudsonPrivateSecurityRealm(false)
hudsonRealm.createAccount('admin','admin')
instance.setSecurityRealm(hudsonRealm)
def strategy = new FullControlOnceLoggedInAuthorizationStrategy()
instance.setAuthorizationStrategy(strategy)
instance.save()
you should deploy your jenkins to ......./tomcat/webapps/root
then the jenkins url should like 'http://localhost:8080/login?from=%2F',
when it is done,just copy code in the file ..../initialAdminPassword
to Administrator password
Type your linux ipaddress:8080/jenkins/.So to unlock your jenkins type ifconfig and know your ip address
For example my ip address for centos is 192.168.2.4
I type 102.168.2.4:8080/jenkins/ in my web browser. Good luck

Apache as proxy with "catch-all"

I want to have Apache proxy to different servers and also have a "catch everything else that doesn't fit" to a server.
I want the following cases where ProxyPass is configured in the proxy's Apache conf file:
ProxyPass / - The "catch-all" where everything else that doesn't fit will go here
ProxyPass /sub1 - going to /sub1 takes me to sub1.domain.com...
ProxyPass /sub2 - going to /sub2 takes me to sub2.domain.com...
I tried the following:
<Location /sub1>
ProxyPass http://sub1.domain.com/
</Location>
<Location /sub2>
ProxyPass http://sub2.domain.com/
</Location>
<Location />
ProxyPass http://sub1.domain.com/
</Location>
This doesn't seem to work as everything defaults to <Location />.
I tried using LocationMatch and wasn't successful in getting sub1 or sub2 to return content. Referred from here: https://serverfault.com/questions/591591/apache-locationmatch-regex-behaviour-does-not-seem-correct
With the above LocationMatch, the headers were working but no content was returned. Going to /A or /B resulted to "Not found".
Does anyone know how I can get this working for Apache or is it even possible?
Try proxypassmatch instead of location directive.