I have a web-service that I would like to expose through the URL foo.com/bar.
However my Apache reverse proxy does not work as intended.
I have created the file 001-default.conf, which contains the following code:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ProxyPass /bar http://foo.com:8080/bar
ProxyPassReverse /bar foo.com:8080/bar
DocumentRoot /var/www/foo/
ServerName info.foo.com
<Directory /var/www/foo>
Options Indexes FollowSymLinks MultiViews Includes
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Right now I receive a 404 error code.
I want to achieve all hits on foo.com/bar to be silently redirected to foo.com:8080/bar, meaning that the user should only see the URL foo.com/bar.
The reverse proxy redirect should also include requests such as foo.com/bar?=foobar.
I did enable proxy_http and proxy:
% sudo a2enmod proxy_http
Considering dependency proxy for proxy_http:
Module proxy already enabled
Module proxy_http already enabled
I hope that there is someone out there that are able to help me with this.
Similar problem that did not solve my problem:
apache reverse proxy changes url Transparent redirect to port 8080
Try and edit the config to:
<VirtualHost *:80>
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost On
ProxyRequests Off
ProxyPass /bar http://foo.com:8080 # Note removed /bar
ProxyPassReverse /bar foo.com:8080 # Note removed /bar
DocumentRoot /var/www/foo/
ServerName info.foo.com
<Directory /var/www/foo>
Options Indexes FollowSymLinks MultiViews Includes
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
You can also try with mod_alias to avoid te /bar/bar issue you might be facing now.
I do not know much about it, see the documentation: http://httpd.apache.org/docs/2.2/mod/mod_alias.html
Try something like adding this to your conf
Alias /bar http://foo.com:8080
Using this you might wan't to remove the proxy.
Related
We are running a node application by reverse proxy. Here is our apache configuration:
<VirtualHost *:80>
ServerName abc.com
Alias /blog/bn /var/www/website/dist/blog/bn
Alias /blog /var/www/website/dist/blog
<Directory /var/www/website/dist/blog/bn>
Options All
AllowOverride All
order allow,deny
allow from all
</Directory>
<Directory /var/www/website/dist/blog>
Options All
AllowOverride All
order allow,deny
allow from all
</Directory>
ProxyPassMatch ^/(blog|blog/bn) !
ProxyPass / http://localhost:5000/
ProxyPassReverse / http://localhost:5000/
</VirtualHost>
Here we are also running other 2 blogs (blog & blog/bn) and url
those applications are:
abc.com/blog
abc.com/blog/bn
Now we are running a new application called: business.com, But we want to redirect from abc.com/example
So we wrote a rule:
ProxyPassMatch /example https://example.com
ProxyPassReverse /example https://example.com
Bu it doesn't work. So how could we redirect by apache?
I have apache2 and tomcat7 in /var/lib/tomcat7. I have my two apps in tomcat webapps: app1 and app2. I have configured my apache virtual host as below:
#
<VirtualHost *:80>
ServerName myweb1.com
ProxyRequests Off
ProxyPass / http://localhost:8080/web1/
ProxyPassReverse / http://localhost:8080/web1/
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
#
myweb1.com is running in a browser but when I make another vhost for web2, myweb2.com is not loading. Yet when I do myweb2:8080/web2 in my browser it's loading the page. What could be the reason for this? Note that myweb2.com has no problem with DNS entry.
I have tried to put web2 into /opt/tomcat9/webapps but the same results come.
We have a configuration where we front the server with EC2 Load Balancer. Because of that, it seems that the "Host" is not properly set when it reaches the server. Because of that we are trying to set the value using the proxy, but it doesn't seem to be working. Below is the configuration:
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin admin#test.com
DocumentRoot "/mnt/dataebs/apache/test"
ServerName www.test.com
ServerAlias www.test.com
ErrorLog "/mnt/dataebs/apache/test-error.log"
CustomLog "/mnt/dataebs/apache/test-access.log" common
<Directory "/mnt/dataebs/apache/test">
Options Indexes FollowSymLinks Includes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
RequestHeader set Host "www.test.com"
RequestHeader set Accept-Encoding "gzip, deflate"
ProxyPass /fabric http://<ip_address>/fabric
ProxyPassReverse /fabric http://<ip_address>/fabric
ProxyPassReverseCookiePath / /
</VirtualHost>
I have looked around for potential solution, but so far I haven't found one that actually solved the problem. I have also doubled checked to make sure mod_headers is enable:
$ httpd -t -D DUMP_MODULES | grep header
Syntax OK
headers_module (shared)
Is there something else we need to include in the configuration? How do you normally deal with this kind of case where the server is fronted by a load balancer?
There is a specific directive in mod_proxy for that called:
ProxyPreserveHost
Just define it and set it to "on"
I have a domain www.example.com hosted in one location.
I have created another account with a different hosting provider that allows me to create subdomains: www.test1.example.com and www.test2.example.com
I am putting a custom page for each of the subdomains when the user goes to test1.example.com, test2.example.com....
After the user logs in on this custom page, I want to maintain the subdomain (of test1.example.com) but internally have all requests point to www.example.com.
I am running the custom pages on Apache and the domain pages on Apache Tomcat - I think that using 'mod_rewrite' is the way to go?
Put the following in a .htaccess file in your subdomain's document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test1\.example\.com$
RewriteRule ^/(.*) http://example.com/$1 [redirect,last]
To enable mod_rewrite on a modern Ubuntu web server run this command:
sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
Make sure AllowOverride is set to "All" in your VirtualHost configuration (for example /etc/apache2/sites-available/default):
<Directory /var/www/document/root/>
AllowOverride All
</Directory>
then restart Apache:
sudo /etc/init.d/apache2 restart
So, basically the answer I found that worked was to use mod_proxy. I enabled that as an Apache module and included the following in my httpd-vhosts.conf file.
NameVirtualHost *:80
<VirtualHost *:80>
ServerName test1.example.com
DocumentRoot "location_of_the_custom_page"
ErrorLog "logs\errors.log"
<directory "D:\wamp\www\capitalfloat">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
</directory>
</VirtualHost>
<VirtualHost *:80>
ServerName localhost2
ServerAlias *.example.com
ErrorLog "logs\errors.log"
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://www.example.com
ProxyPassReverse / http://www.example.com
</VirtualHost>
I also had to include 'http://www.example.com' and 'test1.example.com' in the Windows Host File (For me, C:\Windows\System32\drivers\etc\hosts). In my custom login page, the request goes to 'example.com' and all subsequent requests are sent to 'www.example.com' but the url still shows 'test1.example.com/...'
I have Apache fronting Tomcat and using *mod_proxy_ajp* to pass requests to Tomcat using the following in the VirtualHost config:
<Directory "/var/www/mysite">
Options +Indexes MultiViews
AllowOverride All
Order allow,deny
allow from all
DirectoryIndex index.jsp
</Directory>
<Proxy balancer://tomcatserversMysite>
BalancerMember ajp://localhost:8011 route=mysiteA retry=60
</Proxy>
<Location />
Allow From All
ProxyPass balancer://tomcatserversMysite/ stickysession=JSESSIONID nofailover=off
</Location>
I have a .htaccess file that contains only:
deny from all
but it does not seem to get read.
Is it possible to get Apache to check the htaccess file before forwarding to the proxy, and if so can anyone suggest where I am going wrong?
As noted above:
If I add Include /var/www/mysite/.htaccess in the <Location /> and remove the 'Allow From All' then it works but I require a HTTPD restart to pick up the change in the htaccess file which is certainly not ideal if I ever wanted to modify the htaccess on the fly.