Apache Redirect to two different servers bases on URL - apache

I want to do the following:
I've a server A (http://server-a:9000/) and the server B (http://server-b:8000/). Additionally I've installed an Apache running on port 80.
When I access the apache with http://localhost/product I want to pass this request to http://server-a:9000/product
and
when I access the apache with http://localhost/details I want to pass the request to http://server-b:8000/details.
I'v got this working with the following configuration:
ProxyPass /product http://server-a:9000/product
ProxyPassReverse /product http://server-a:9000/product
ProxyPass /details http://server-b:8000/product
ProxyPassReverse /details http://server-b:8000/product
But with this configuration the original URL http://localhost/product is replaced by http://server-a:9000/product.
How can I configure my Apache so that it doesn't replace the URL? The displayed URL should always be http://localhost/product.
Thank you in advance
Torben

Related

Proxypass and reverse proxy from apache to nginx

I have subdomain website http://subdomain.mywebsite.com/path which is hosted on Siteground and running on nginx server. I want the users should be able to access the above path or its subpaths through main website URL lets say http://mywebsite.com/path which is running on apache server.
I have tried to proxypass and reverseproxypass using following in apache configuration file on my main website:-
<Location "/path">
ProxyPass "http://subdomain.mywebsite.com/path"
ProxyPassReverse "http://subdomain.mywebsite.com/path"
</Location>
When i access the page http://mywebsite.com/path I get 404 page of siteground whereas the same path is directly accesible using http://subdomain.mywebsite.com/path.
I have been trying to find the solution but could not get it working.
You can use the below configuration:
ProxyPass /path http://subdomain.mywebsite.com/path
ProxyPassReverse /path http://subdomain.mywebsite.com/path

How to redirect URL with port to URL with context?

I have a server with apache(2.4.18) installed
I have installed multiple applications on the server like Grafana, Sonarqube, and MySQL enterprise monitor(MEM)
Each application has URL like this
http://test.com:9000
http://test.com:3000
I am looking for a solution which allows me to redirect this URL with the port to URL with context, something like that
http://test.com:9000 --> http://test.com/sonar
http://test.com:3000 --> http://test.com/grafana
I have added some code in /etc/apache2/sites-enabled/000-default.conf file
Redirect permanent /sonar http://test.com:9000
Redirect permanent /grafana http://test.com:3000
but when I enter http://test.com/sonar in the web browser it redirects to http://test.com:9000 URL only
I want http://test.com/sonar this URL to persists on Web browser
If you use Redirect permanent, server will send 301 response back to client (along with new Location). That will result in browser issuing a new request, this time to new Location, and also new location will be shown in browser address bar.
What you need is Reverse Proxy. For this you need to make sure that mod_proxy is enabled in your apache configuration (usually it is enabled by default), and put something like this in your .conf file:
ProxyPreserveHost On
ProxyPass /sonar http://127.0.0.1:9000
ProxyPassReverse /sonar http://127.0.0.1:9000
ProxyPass /grafana http://127.0.0.1:3000
ProxyPassReverse /grafana http://127.0.0.1:3000
You will probably also have to make your applications aware that they are running under non-root context (by making some configuration changes):
http://docs.grafana.org/installation/behind_proxy/
https://docs.sonarqube.org/latest/setup/install-server/
You need to proxy requests and not redirect them.
Use a ProxyPass directive as mentioned in the official apache proxy documentation
For example add this location block inside your configuration:
<Location "/sonar">
ProxyPass "http://test.com:9000"
</Location>

Apache hybris configuration to proxy pass HTTP and HTTP(S) yacceleratorstorefront (electronic store) URL to Hybris Server

I am trying to access the yacceleratorstorefront/electronics/en/?site=electronics URL from apache web server to Hybris where the electronic store URL is configured. The electronic store URL is accessible and working from any of the server in environment if apache web server is BY PASSED
http://10.0.1.141:9001 is my Hybris server.
ERROR ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
HTTP Status 500 - Cannot find CMSSite associated with current URL ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
type Status report
message Cannot find CMSSite associated with current URL
description The server encountered an internal error that prevented it from fulfilling this request.
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Any suggestion or advice is highly appreciated. Thank you in advance.
-Regards, S#BS
------------------------------------------------httpd Code below----------------------------------------------------
<VirtualHost *:80> ProxyPreserveHost On
ProxyPass / http://10.0.1.141:9001/ ProxyPassReverse / http://10.0.1.141:9001/
ServerName localhost</VirtualHost>
<VirtualHost *:443> ServerName localhost
#ProxyRequests Off #ProxyPreserveHost On ProxyPass / https://10.0.1.141:9002/yacceleratorstorefront/electronics/en/?site=electronics ProxyPassReverse / https://10.0.1.141:9002/yacceleratorstorefront/electronics/en/?site=electronics
SSLEngine on SSLCertificateFile /etc/httpd/certs/mysite.com.crt SSLCertificateKeyFile /etc/httpd/certs/mysite.com.key
</VirtualHost>
The error message indicates that you are not setting the ?site=electronics parameter at the http version of you proxy (it also seems to be missing in the proxypass setting for port 80).
I'm not an apache buff but maybe it works if you configure your proxy settings for port 80 in the same way:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://10.0.1.141:9001/?site=electronics
ProxyPassReverse / http://10.0.1.141:9001/?site=electronics
ServerName localhost
</VirtualHost>
Just some more info: Apart from the site parameter approach you can also use a host name approach.
Not sure if you have access to the hybris wiki, but here are some more details:
https://wiki.hybris.com/display/pmtelco/Using+Modulegen+to+Create+a+B2C+Telco+Setup#UsingModulegentoCreateaB2CTelcoSetup-AccessingtheStorefront
(its for Telco accelerator, but it works the same for any other storefront).
Not sure how that works together with apache, I assume you have to setup some sub domains or something.
Does it work if you try to access apache on https directly? (There it seems you have the correct url containing the site parameter).
Note: The site parameter is basically only needed for the first http request of a session. It is used to determine which storefront, i.e. BaseSite is supposed to be used. All subsequent requests (of the same session) shouldn't require the site parameter.
Hope that helps!
Your http config is fine. Your https config is wrong.
Do not put ?site=electronics or anything like that in your apache config.
The site detection works based on the URL. In the sample data you are using that is at least a regex looking for "electronics" in the hostname.
One single apache config will be able to support all sites. You do not need to specify the site. You do not need to specify /yacceleratorstorefront.
Simply edit your hosts file to include "10.0.1.141 electronics.rtfm"
Now access http://electronics.rtfm/
You can avoid adding the site in the URL by going in HMC: WCMS > Websites
Under the Properties tab, add a new URL pattern that will match your site.
Once it is done, URLs that match the site's pattern will automatically use that site.
Using URL patterns for each site will simplify the web server's configuration.

How to have Apache server port 8080 display content from localhost:3080

So I have an application the is bound to localhost:3080. When I locally visit "localhost:3080" the application displays in the browser.
I also have an apache server setup listening to the publicIP:8080.
When I visit the publicIP from the outside world, publicIP:8080 loads up.
How can I have it so that when I visit publicIP:8080, the contents of localhost:3080 are displayed onto it?
Is there a way to forward the contents of localhost:3080 to publicIP:8080?
You can create an apache proxy.For example :
<VirtualHost *:8080>
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:3080/
ProxyPassReverse / http://127.0.0.1:3080/
</VirtualHost>
You will also need to do :
a2enmod proxy
a2enmod proxy_http
service apache2 restart
See more informations there : https://www.digitalocean.com/community/tutorials/how-to-use-apache-http-server-as-reverse-proxy-using-mod_proxy-extension
I assume your application at localhost:3080 acts as a http server.
Then you would simply
ProxyPass "/" "http://localhost:3080/"
Generally its better to use ProxyPass to handle only special locations
<Location "/myCoolApp/">
ProxyPass "http://localhost:3080/"
</Location>
Then if you request http://publicIP:8080/myCoolApp/XYZ your application #3080 will receive the request on URL /XYZ.

Apache mod_proxy not forwarding all requests

I have a Bottle/Python app running on localhost:3000 that I am using Apache mod_proxy to forward requests to. Its working 99% of the time, except when I try and go to a url like:
http://m2t.openseedbox.com/api/upload/http%3A%2F%2Ftorrents.thepiratebay.se%2F6753175%2FPioneer_One_S01E04_720p_x264-VODO.6753175.TPB.torrent
(basically, there is a URL that is a part of the URL but its been run through encodeURIComponent). In this case, Apache is returning its own 404 page and not passing the url through to the backend server.
My apache config is as follows:
<VirtualHost *:80>
ServerName m2t.openseedbox.com
ProxyPass / http://127.0.0.1:3000/ retry=0
ProxyPassReverse / http://127.0.0.1:3000/
ProxyPreserveHost On
</VirtualHost>
Why is Apache not proxying this URL? (you can visit it yourself to see the Apache 404 page where a Bottle page should be)
EDIT: I've worked around it by passing the URL as a GET parameter. I still dont know why Apache isnt working as advertised though...
By default, Apache doesn't pass through urls with %2F in them. See the link below for more info.
%2F in URL breaks and does not reference to the .php file required