Keycloak as subresource behind Apache2 - proxy

Keycloak is running on Docker image jboss/keycloak and environment variable PROXY_ADDRESS_FORWARDING is set to true. I would like to setup Keycloak behind Apache2 webserver as subresource. When I my Apache configuration is:
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
I have access to KeyCloak, however I'm loosing access to another resources on the server, for example /panel or /wordpress. I've tried to do the following:
ProxyPass /keycloak/ http://127.0.0.1:8080/
ProxyPassReverse /keycloak/ http://127.0.0.1:8080/
But with above configuration I'm redirected to /auth on a server instead of Keycloak's auth.
Could you help me to configure Keycloak as a subresource on Apache2 webserver?

I found a way to make it work. I created the following Dockerfile:
FROM jboss/keycloak
RUN sed -i -e 's/<web-context>auth<\/web-context>/<web-context>keycloak\/auth<\/web-context>/' $JBOSS_HOME/standalone/configuration/standalone-ha.xml
after rebuilding an image I've changed my Apache2 configuration as follows:
ProxyPass /keycloak/ http://127.0.0.1:8080/keycloak/
ProxyPassReverse /keycloak/ http://127.0.0.1:8080/keycloak/
Now KeyCloak works from the same domain as a subresource.

Related

jhipster ssl ubuntu apache2 setup

I have generated my app using Jhipster. Configured it to run on amazon ec2 with Ubuntu 16.x and apache with following configuration and godaddy a record. When I hit the website url it maps and renders the site without any issues.
apache2 configuration
<VirtualHost *:80>
ServerName 111.22.33.444
ProxyPreserveHost On
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://111.22.33.444:8080/
ProxyPassReverse / http://111.22.33.444:8080/
</VirtualHost>
Nest step, trying to configure SSL. I have bought the SSL from godaddy for my domain, configured it and uploaded the *.crt files into /etc/apache2/ssl. I quickly realized just by adding another virtual host configuration for port 443 will not work because JHipster app is running on 8080. I went back and looked at https://www.jhipster.tech/production/ and they have instructions for configuring SSL with HTTPS configuration with a front-end proxy and this where I got lost and am unable to configure SSL and serve up my domain on https.
What is not clear is can I still run the app on 8080 and simply follow the instructions under HTTPS configuration with a front-end proxy? First, I configured apache using "lets encrypt" using the following command
sudo certbot --apache -d doamin.com --agree-tos -m info#domain.com --redirect
it failed saying
Failed redirect for domain.com
Unable to set enhancement redirect for domain.com
It didn't work.
What are the changes for Jhipster application that I need to do? Should it run on 443 or continue to run 8080 and update virtual host configuration? How should i configure virtual host?
I have searched high and low with no instructions. Any direction is much appreciated.
Assuming your app is available at http://127.0.0.1:8080/, you can successfully configure Apache for HTTPS with Certbot by following the below steps.
Setup server with:
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update
sudo apt-get install python-certbot-apache apache2
Start with the config:
<VirtualHost *:80>
ServerName example.com
ServerAlias example.com
ProxyPass / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/
ProxyPreserveHost On
ProxyRequests Off
</VirtualHost>
Enable plugins and restart Apache2, making the app accessible at the domain configured above:
a2enmod headers proxy proxy_http
service apache2 restart
Then run certbot with the instructions in the docs:
sudo certbot --apache -d example.com
After that, your app will be accessible at the domain you configured and served via HTTPS.

Setup apache2 to forward to Glassfish 4

I have a fresh Ubuntu 16.04 server and a simple html website running with apache 2.
An SSL certificate is also installed. Apache2 is already configured to forward automatically to https.
Furthermore I have a java application running on Glassfish 4 under contextroot myApp. I can access it under http://mydomain.io:8080/myApp
How can I configure apache to forward all requests https://mydomain.io/myApp/ to Glassfish. I don't want to use mod_jk, just apache.
Thanks
UPDATE
In the mean time I tried with mod_rewrite this:
ProxyPass /myApp/ http://localhost:8080/myApp/
ProxyPassReverse /myApp/ http://localhost:8080/myApp/
in /etc/apache2/sites-enabled/000-default.conf
but it's not working!
Finally I solved the problem by inserting following lines
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
in the VirtualHost configuration file located in /etc/apache2/sites-available/. Like suggested in this website.

Mod Rewrite or Mod Proxy setup for tomcat and apache

Assuming I have a domain name called "stackoverflow.com"
I have apache tomcat 7 running an application with context root as /mainsite
I can access this locally as http://stackoverflow.com:8080/mainsite
Apache tomcat is running on 8080 port.
I have apache web server running two more PHP applications on port number 80
one of the Apache application is blog
antoher apache application is forum
my url to access blog is "https://stackoverflow.com/blog"
my url to access forum is "https://stackoverflow.com/forum"
I want to send all requests with url like https://stackoverflow.com/* to mainsite on tomcat
Any url with https://stackoverflow.com/blog or https://stackoverflow.com/forum to be served by apache.
Please let me know how to do this.
I tried some thing like this in httpd.conf
but it is sending every call made to /mainsite.
ProxyPass /blog https://stackoverflow.com/wordpress-3.8.2/wordpress/
ProxyPassReverse /blog https://stackoverflow.com/wordpress-3.8.2/wordpress/
ProxyPass /forum http://localhost/phpBB3/
ProxyPassReverse /forum http://localhost/phpBB3/
ProxyPass / http://localhost:8080/mainsite/
ProxyPassReverse / http://localhost:8080/mainsite/
Thanks in advance for your help.
Do the others work if you remove the last two lines? Proxying the root directory could be a problem, because that also includes the subdirs. I suggest you rewrite the last lines to
ProxyPass /mainsite http://localhost:8080/mainsite/
ProxyPassReverse /mainsite http://localhost:8080/mainsite/
And then add a permanent redirect in the index.html of the apache running at port 80.

Apache & Tomcat: ProxyPass and ProxyPassReverse

I'am having troubles configuring Apache and Tomcat, this is the scenario:
I have an Apache Web Server, running and working normally, I can access to this one just typing:
http://localhost
Also, in this host, I have a Tomcat running and working fine; I've created a mini web-app which files are inside "prueba" directory, I can access typing:
http://localhost:8080/prueba
(I know that Apache is running in 80 port and Tomcat in 8080)
What I want to do is that througt Apache an user can access to 'pruebas'(running on Tomcat), I mean:
http://localhost/prueba
I've readen a lot of this, and I think that there are 2 ways to do this, and I've decided enabling the proxy modules(proxy and proxy_ajp, with a2enmod), also I've readed I must edit this file: sites-available/default, this is the content:
NameVirtualHost *:80
<VirtualHost *:80>
ServerName 127.0.0.1
DocumentRoot /var/www
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /static/ !
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
.
.
.
Alias /static/ "/apache/www/"
</VirtualHost>
But this hasn't work propperly :(
I have to say that I've tried whit many changes, ont this 2 lines, like:
ProxyPass /prueba ajp://localhost:8009/prueba
ProxyPassReverse /prueba ajp://localhost:8009/prueba
or
ProxyPass / ajp://localhost:8009/prueba
ProxyPassReverse / ajp://localhost:8009/prueba
(each time I edit the file, I restart apache)
But when I access to [http://localhost/prueba/], I have:
Service Temporarily Unavailable
Has anyone knows why?
Thanks in advance guys.
Pd: I'm working with apache 2.2.17 and tomcat6.
You have to put
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
on your apache virtual host
Then you have to uncomment ajp listener in tomcat
<Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />
Then you have to configure host and context path in server.xml
REFF:
http://www.ntu.edu.sg/home/ehchua/programming/howto/ApachePlusTomcat_HowTo.html
Hope this will help you..
ProxyPassReverse defines the URL Apache httpd should rewrite the URLs to, which would redirect to the proxied (hidden) URL. Because of this, you should change your ProxyPassReverse line to something like this:
ProxyPassReverse / http://localhost/prueba/
See also: http://httpd.apache.org/docs/2.2/mod/mod_proxy_ajp.html#usage
Try this:
ProxyPass /prueba/ http://localhost:8009/prueba/
ProxyPassReverse /prueba/ http://localhost:8009/prueba/
and then hit the following URL from browser: http:// localhost/prueba/
note: it is mandatory to add "/prueba/"
Service not available might be coming due to SELinux ,try disabling SE Linux : setenforce 0
you may try adding:
ProxyPreserveHost On
From the documentation:
"When enabled, this option will pass the Host: line from the incoming request to the proxied host, instead of the hostname specified in the ProxyPass line.
This option should normally be turned Off. It is mostly useful in special configurations like proxied mass name-based virtual hosting, where the original Host header needs to be evaluated by the backend server."
You stated: I can access typing:
http://localhost:8080/prueba
but the following does not work:
ProxyPass /prueba/ http://localhost:8009/prueba/
8080 != 8009
make sure your port numbers are the same
Port 8009 is Tomcat so use ajp instead of http
ProxyPass /prueba/ ajp://localhost:8009/prueba/
ProxyPassReverse /prueba/ ajp://localhost:8009/prueba/

Apache how to set company proxy to location

i am trying to set a ProxyPass to my Apache server. I want to set the / location to http://google.de. The problem is, that i am running against the company's proxy server and i need to 'tell' my Apache server that it should use the company proxy server.
This is what i configured:
ProxyRequests Off
ProxyPass / http://www.google.de
ProxyPassReverse / http://www.google.de
is there something like a "setProxy" order? for example the proxyserver of my company is: proxy.company.com:81.
Thanks
I solved the problem, one just need to add the ProxyRemote command:
ProxyRemote * http://proxy.mycompany.com:81
<Location /test>
ProxyPass http://www.heise.de
ProxyPassReverse http://www.heise.de
</Location>
That should work fine. The only problem is, that the relative paths make trouble. I canĀ“t see images and the links are dead.

Resources