Using Apache2 as proxy toward Tomcat7 - apache

Tomcat7 server hosts a website on my machine and I want to use Apache2 as a proxy to see it through my browser: http://localhost:8080/examples as http://localhost/examples.
I have installed Apache2 and Tomcat7, they both work on my computer.
I have loaded mod_proxy and mod_proxy_http modules
In my http_vhosts.conf file I have:
<VirtualHost *:80>
ProxyRequests off
SSLProxyEngine on
ProxyPreserveHost on
ServerName mathost.workstation.org
ProxyPass /examples http://localhost:8080/examples
ProxyPassReverse /examples http://localhost:8080/examples
ProxyRequests Off
</VirtualHost>
In my proxy_http.conf I have:
ProxyRequests Off
ProxyPreserveHost On
<Location "/examples/">
ProxyPass /examples http://localhost:8080/examples
ProxyPassReverse /examples http://localhost:8080/examples
Order deny,allow
Allow from all
</Location>
It doesn't work, apache logs say "GET /examples/ HTTP/1.1" 404 207".

Solved.
The problem was the path "/example/". I had to use the right url: "/example".
Then, http_vhosts.conf had 2 vhost on port 80, absolute useless.

Related

Apache2 Proxy wrong routing

I use apache2 as a proxy to distribute request for different URLs to different lxc containers on ubuntu 16.04 LTS
For example:
www.adomain.com is proxied to 10.0.3.100
www.bdomain.com is proxied to 10.0.3.101
etc.
In principle this works but fine, but now I see a strange behaviour.
Config file bbb.adomain.com:
<VirtualHost bbb.adomain.com:80>
ServerName bbb.adomain.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://10.0.3.104/
ProxyPassReverse / http://10.0.3.104/
<Location />
Order allow,deny
Allow from all
</Location>
</VirtualHost>
This works fine, every request for bbb.adomain.com ist proxied to 10.0.3.104
However, also requests to xxx.bdomain.com are proxied to 10.0.3.104, too. But xxx.bdomain.com is NOT configured as virtual host / servername in ANY apache .conf file.
How can I configure apache2, that any URL which is not configured as virtual host / servername is NOT proxied?
How can I debug apache2 to find out, why this domain xxx.bdomain.com is proxied?
By the way - the first apache config file is 000.conf:
<VirtualHost *:80>
ServerName catchall
<Location />
Order allow,deny
Deny from all
</Location>
You can try this basic configuration :
<VirtualHost *:80>
ServerName bbb.adomain.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://10.0.3.104/
ProxyPassReverse / http://10.0.3.104/
<Location />
Order allow,deny
Allow from all
</Location>
</VirtualHost>
<VirtualHost *:80>
ServerName xxx.bdomain.com
DocumentRoot /var/www/example
</VirtualHost>
Using the following steps:
1) Update virtual file:-
<VirtualHost *:80>
ServerAdmin admin#test.com
ServerName mysite.com
ServerAlias www.mysite.com
ProxyRequests Off Order deny,allow Allow from all
<Location />
ProxyPass http:// mysite.com:8000/
ProxyPassReverse http:// mysite.com:8000/
</Location>
</VirtualHost>
2) Enabling Necessary Apache Modules
To enable these four modules, execute the following commands in succession.
sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests
3) To put these changes into effect, restart Apache.
sudo systemctl restart apache2

Httpd.conf redirect to external url apache tomcat

I have an application that makes a call to an external URL.
When I try to run it in localhost only some static HTML files which are in the localhost get loaded.
Any files located on the external URL doesn't load. It returns a 404 not found error.
I am using Apache sever, and Tomcat to run the application.
My Httpd.conf file has the following changes:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests On
ProxyVia On
ServerName localhost
ServerAlias *.localhost
ProxyPass /ab-ux-sass http://localhost:8080/ab-ux-sass
ProxyPassReverse /ab-ux-sass http://localhost:8080/ab-ux-sass
ProxyPass /ux-services https://boot.lender.com/ux-services
ProxyPassReverse /ux-services
https://boot.lender.com/ux-services
</VirtualHost>
what config changes needs to be made?
Made the following changes in the Httpd.conf file. It is working now.
<VirtualHost *:80>
ServerName dev.localhost
SSLProxyEngine on
ProxyRequests Off
<Proxy *>
Order allow,deny
Allow from All
</Proxy>
ProxyPass /ab-ux-sass http://localhost:8080/ab-ux-sass
ProxyPassReverse /ab-ux-sass http://localhost:8080/ab-ux-sass
ProxyPass /ux-services https://boot.lender.com/ux-services
ProxyPassReverse /ux-services
https://boot.lender.com/ux-services
</VirtualHost>

Error in Redirect from Apache to Tomcat using mod_proxy

I have apache and Tomcat in my server and im using mod_proxy to redirect from Apache to Tomcat... the apache is running on port 80 and tomcat is running on port 8080
here is my virtual host :
<VirtualHost *:80>
ServerName www.example.ir
ServerAlias example.ir
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://localhost:8080/example
ProxyPassReverse / http://localhost:8080/example
<Location "/">
Order allow,deny
Allow from all
</Location>
</VirtualHost>
But the problem is when I try www.example.com i get the following error :
HTTP Status 404 - /exampleexample/
so whats wrong with my configuration ?
Thanks and sorry for my poor english
Do you want to execute Tomcat's examples webapp? If this is the case, try following configuration:
ProxyPass / http://localhost:8080/examples/
ProxyPassReverse / http://localhost:8080/examples/
After restarting your Apache, navigate to http://yourhost/.
Hope this helps.

Avoid the conflict on port 80 between nodejs and apache

The goal is to listen on port 80 with nodejs without killing apache.
I have to say my knowledges in network are very basic.
UPDATE
I am trying to use ProxyPass ProxyPassReverse on my local machine but there is something wrong.
Alias /test /media/www-dev/public/test
<Directory /media/www-dev/public/test>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass /test http://localhost:3000/
ProxyPassReverse /test http://localhost:3000/
</Location>
When i launch http://localhost/test on my browser i get a message Cannot GET /test/, if i stop to listen on the port 3000, then i get 503 Service Temporarily Unavailable my node app is listening on the port 3000.
If if commente the "Proxy" lines, i can reach the URL http://localhost/test again.
Why can i not access the URL http://localhost/test ? Is it because the proxy try to reach http://localhost:3000/ instead following the path of the alias /test ?
Thanks !
you need to create a virtual host in apache for your node app and proxy over the requests.
here is what mine looks like in /etc/apache/sites-available/dogself.com
<VirtualHost 69.164.218.75:80>
ServerName dogself.com
ServerAlias www.dogself.com
DocumentRoot /srv/www/dogself.com/public_html/
ErrorLog /srv/www/dogself.com/logs/error.log
CustomLog /srv/www/dogself.com/logs/access.log combined
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</Location>
</VirtualHost>
It sounds like you have a lot to research before you can get this working though. start reading docs
Alternative approach for a virtual host would be the following
<VirtualHost *:80>
ServerAdmin info#DOMAIN.com
ServerName DOMAIN.com
ServerAlias www.DOMAIN.com
ProxyRequests off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:3000/
ProxyPassReverse http://localhost:3000/
</Location>
</VirtualHost>
To fix the Internal Server ERROR just enable the right apache extension.
sudo a2enmod proxy_http
sudo service apache2 restart

Issues Setting up a reverse proxy in Apache

My roommate and I each have a separate webserver we are trying to set up. We are trying to use mod_proxy so that his server will forward requests to my machine (we have two seperate machines behind one router) based on the server name. I've given the basics of what we have in our apache config currently but we are getting a 403 Forbidden error when trying to access the second domain (the first, www domain, works fine).
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www
ServerName www.<domain1>.com
</VirtualHost>
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass / http://<IP addr of other box>:80
ProxyPassReverse / http://<IP addr of other box>:80
ServerName <dummydomain>.gotdns.com
</VirtualHost>
Your mods-enabled/proxy.conf might be blocking any proxy requests (it's deny all by default). It should include the following instead:
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
EDIT: Also make sure that the mod_proxy submodules are sym linked into mods-enabled (in this case, the http sub module which is mods-available/proxy_http.load)
Just put both routes:
<VirtualHost *:80>
DocumentRoot "/app/"
ProxyPreserveHost On
ProxyRequests Off
ServerName app.yourdomain.com
ProxyPass /app http://yourIP:yourPort/app/
ProxyPassReverse /app http://yourIP:yourPort/app/
ProxyPass / http://yourIP:yourPort/app/
ProxyPassReverse / http://yourIP:yourPort/app/
</VirtualHost>
<Location "/app/" >
ProxyPass "http://yourIP:yourPort/app/"
ProxyPassReverse "http://yourIP:yourPort/app/"
ProxyPassReverseCookiePath "/app/" "/app/"
ProxyHTMLEnable Off
ProxyHTMLExtended On
ProxyHTMLURLMap "/app/" "/app/"
Order allow,deny
Allow from all
</Location>
This worked form me