Setting up mod_jk redirect in Hybris - apache

I have installed apache httpd 2.2.15 in my app server. I need to get the login page(https://ip_address:9002/xxstorefront/xx/en/USD/login) when I hit on https://dev.xxyy.com/login. I have installed SSL certificate for my domain and set below redirect rules.
ProxyPass /login http://localhost:9001/xxstorefront/xx/en/USD/login
ProxyPassReverse /login http://localhost:9001/xxstorefront/xx/en/USD/login
ProxyPass /login https://localhost:9002/xxstorefront/xx/en/USD/login
ProxyPassReverse /login https://localhost:9002/xxstorefront/xx/en/USD/login
RewriteEngine On
RewriteRule ^(.*)/login http://%{ip_address:9001}$1/{xxstorefront/xx/en/USD/login}$2 [L,R]
When I hit on https://dev.xxyy.com/login, I get below error,
Not Found 
The requested URL /login was not found on this server.
Apache/2.2.15 (CentOS) Server at dev.xxyy.com Port 443
When I hit on https://dev.xxyy.com, I get the apache default homepage.
Pls guide me how should I set the redirect rules.

Your configuration is invalid. Those two lines:
ProxyPass /login https://localhost:9002/xxstorefront/xx/en/USD/login
ProxyPassReverse /login https://localhost:9002/xxstorefront/xx/en/USD/login
overwrite those two:
ProxyPass /login http://localhost:9001/xxstorefront/xx/en/USD/login
ProxyPassReverse /login http://localhost:9001/xxstorefront/xx/en/USD/login
Rewite mechanism probably does not work at all:
RewriteEngine On
RewriteRule ^(.*)/login http://%{ip_address:9001}$1/{xxstorefront/xx/en/USD/login}$2 [L,R]
I think this configuration should solve your problem:
<VirtualHost *:80>
ServerName dev.xxyy.com
ProxyPreserveHost On
ProxyPass / http://localhost:9001/xxstorefront/xx/en/USD/
ProxyPassReverse / http://localhost:9001/xxstorefront/xx/en/USD/
</VirtualHost>
<VirtualHost *:443>
ServerName dev.xxyy.com
SSLEngine on
// other SSL directives
ProxyPreserveHost On
ProxyPass / https://localhost:9002/xxstorefront/xx/en/USD/
ProxyPassReverse / https://localhost:9002/xxstorefront/xx/en/USD/
</VirtualHost>
It defines two virtual hosts which work as proxies and map all requests to xxstorefront/xx/en/USD/...:
http://dev.xxyy.com/(.*) → http://localhost:9001/xxstorefront/xx/en/USD/(.*)
https://dev.xxyy.com/(.*) → https://localhost:9002/xxstorefront/xx/en/USD/(.*)

Related

Apache Reverse Proxy https to http? does SSL certificate is mandatory

Hi I have been working on setting up my webserver. We have the company domain https://www.company.com which is already with https, which we are unable to get SSL certificates. I wanted to make use this domain and deploy my app (http) by adding https//www.company.com/myapp this myapp and map this url to the http app which is deployed.
I am using the configuration shown below for your reference. I have a doubt only if we get SSL only we progress or their is some way to map this domain to my app running on port 8000.
<VirtualHost *:443>
ServerName company.com
ServerAlias www.company.com
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /myapp http://localhost:8000/
ProxyPassReverse /myapp http://localhost:8000/
RewriteEngine On
RewriteCond %{ENV:HTTPS} on
RewriteRule /(.*) http://localhost:8000/$1 [R=301,L]
</VirtualHost>
if you want to use HTTP, use port 80 instead of 443. you can also use both separately for HTTP and HTTPS connection.
<VirtualHost *:80>
ServerName company.com
ServerAlias www.company.com
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /myapp http://localhost:8000/
ProxyPassReverse /myapp http://localhost:8000/
RewriteEngine On
..................
As per server requirements
..................
</VirtualHost>
<VirtualHost *:443>
ServerName company.com
ServerAlias www.company.com
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /myapp http://localhost:8000/
ProxyPassReverse /myapp http://localhost:8000/
RewriteEngine On
RewriteCond %{ENV:HTTPS} on
RewriteRule /(.*) http://localhost:8000/$1 [R=301,L]
</VirtualHost>

Apache proxy pass all urls and rewrite only one specific url

I have a website running the Ghost Blog engine in the back end. I configured the subdomain blog.domain.com to proxy to ghost engine (localhost:2368) but I need to verify that subdomain in google search console so I need the blog.domain.com/googlefile.html to return a specific string (that same string is available at domain.com/googlefile.html). How do I do that?
My virtual host config:
ServerName blog.example.com
ServerAlias *.blog.example.com
#here is what I tried
#RewriteEngine On
#RewriteCond %{HTTP_HOST} blog\.example\.com
#RewriteRule googlefile.html https://example.com/googlefile.html
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:2368/
ProxyPassReverse / http://127.0.0.1:2368/
Btw. all domains are https.
The solution was to enable SSLProxyEngine so I can proxy https urls and also use mod_rewrite with proxy ignore url
SSLProxyEngine On # enable SSLProxyEngine
ServerName blog.example.com
ServerAlias *.blog.example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} blog\.example\.com
RewriteRule googlefile.html https://example.com/googlefile.html [P]
ProxyPreserveHost On
ProxyPass googlefile.html ! # ignore the rewrited url
ProxyPass / http://127.0.0.1:2368/
ProxyPassReverse / http://127.0.0.1:2368/

Apache 2.2 to 2.4 too many redirects

I have an old server which uses httpd 2.2 and this configuration works fine redirecting HTTP requests to HTTPS.
Moving to CentOS and upgrading to httpd 2.4 the existing configuration causes a too many redirects to occur.
<VirtualHost _default_:80>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>
<VirtualHost _default_:443>
SSLEngine on
... SSL Setup ...
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / ajp://localhost:8009/
ProxyPassReverse / ajp://localhost:8009/
</VirtualHost>
I'm using tomcat which is listening on port 8009 internally, I'm not sure why is it happening.
SUGGESTED
The ProxyPassReverse directive doesn't work well with ajp.
Switch to HTTP/HTTPS
Remove the ProxyPassReverse directive
Validate you have set RemoteIPHeader X-Forwarded-For, X-Forwarded-Host, X-Forwarded-Port and X-Forwarded-Proto appropriately as well

Apache forward proxy by url parameter

I want redirect any access whose URL parameter is "deep" to local server, and redirect other access to other server.
Forward a request like the following:
① url parameter starting with deep
http*://hostname/bdd?deep=1
→
http*://127.0.0.1:8080/bdd
② other url
→
http*://10.137.213.101:8080/bdd
I am setting my apache conf as the following, but it still does not work.
RewriteEngine On
RewriteCond %{QUERY_STRING} ^deep
RewriteRule "^/bdd(.*)$" /dataviewlinks/ [L]
ProxyPass /dataviewlinks http*://127.0.0.1:8080/bdd
ProxyPassReverse /dataviewlinks http*://127.0.0.1:8080/bdd
ProxyPass /bdd http*://10.137.213.101:8080/bdd
ProxyPassReverse /bdd http*://10.137.213.101:8080/bdd
What could be the solution?
I have done it like this in the past to redirect any network access on port 8080 to another directory.
<VirtualHost *:8080>
ServerName 127.0.0.1
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyRequests On
ProxyPreserveHost On
ProxyPass "/" "http://10.137.213.101:8080/bdd"
ProxyPassReverse "/" "http://10.137.213.101:8080/bdd"
</VirtualHost>
Maybe this would work for you as well.
Also make sure you have enabled proxy mod sudo a2enmod proxy and restart apache

How to properly redirect a url to the exist-db port

In apache virtual host I attempted to redirect /db to the exist database. This works only momentarily such that it shows the exist welcome screen but then exist redirects to the dashboard and that page is not found.
ProxyPreserveHost On
ProxyRequests Off
ProxyPass /db http:**localhost:8899
ProxyPassReverse /db http:**localhost:8899
I'd like to set things up so I can do REST queries like /db/rest
What am I doing wrong?
Thanks
You need to do some URL rewriting and cookie handling: the following example maps "/" and "myapp2". It is possible to map to /rest/db/myapp1 too.
<VirtualHost *:80>
ProxyRequests off
ServerName myserver
ProxyPass /myapp2/ http://localhost:8080/exist/apps/myapp2/
ProxyPassReverse /myapp2/ http://localhost:8080/exist/apps/myapp2/
ProxyPass / http://localhost:8080/exist/apps/myapp1/
ProxyPassReverse / http://localhost:8080/exist/apps/myapp1/
ProxyPassReverseCookieDomain localhost myserver
ProxyPassReverseCookiePath / /exist
RewriteEngine on
RewriteRule ^/(.*)$ /$1 [PT]
</VirtualHost>