Apache2 send request to a path and all its subpaths to another source - apache

I have a server running Apache 2.2, where i have an instance of WordPress installed.
I also have a tomcat7 server running with a webapp on port 8080.
I wish to send everyrequest to the tomcat server but the blog ones like: /blog, /blog/, /blog/2017/02/10/blog-title-here/, etc...
i currently managed to have /blog going to the right place, but not the individual posts, they always go to the tomcat7 and i don't know why.
Here's my configuration file:
<VirtualHost *:80>
RequestHeader set X-Forwarded-Proto "http"
AddDefaultCharset utf-8
ServerAdmin contact#example.com
ServerName server.example.com
<Directory />
Options FollowSymLinks
</Directory>
Alias "/blog" "/var/www/www.example.com"
<Directory /var/www/www.example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost on
ProxyPass "/blog" "!"
ProxyPass "/" "http://localhost:8080/"
ProxyPassReverse "/" "http://localhost:8080/"
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
RequestHeader set X-Forwarded-Proto "https"
AddDefaultCharset utf-8
ServerAdmin webmaster#example.com
ServerName server.example.com
<Directory />
Options FollowSymLinks
</Directory>
Alias "/blog" "/var/www/www.example.com"
<Directory /var/www/www.example.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost on
ProxyPass "/blog" "!"
ProxyPass "/" "http://localhost:8080/"
ProxyPassReverse "/" "http://localhost:8080/"
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/wildcard.example.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/wildcard.example.com.key
SSLCertificateChainFile /etc/apache2/ssl/rapidssl_intermediate.crt
</VirtualHost>
The main parts being:
Alias "/blog" "/var/www/www.example.com"
(...)
ProxyPass "/blog" "!"
ProxyPass "/" "http://localhost:8080/"
Where i'm aliasing everything starting with /blog and sending it to where the wordpress is and not proxying it. And proxying everything from / to tomcat.
The only thing i can't work out why it's not working is requests to /blog/ not working.
I've tried ProxyPassMatch, and AliasMatch, can't do it.
Any help appreciated.

Related

Configure multiple virtualhosts in apache with different ports

I want to redirect my apache server to two different urls. I am creating the two different virtualhost as below.
first virtualhost as below
<VirtualHost localhost:80>
ProxyPass /app1 http://localhost:5002/app1
ProxyPassReverse /app1 http://localhost:5002/app1
<Location />
#Options FollowSymLinks
AllowOverride All
Require all granted
</Location>
</VirtualHost>
second virtual host as:
<VirtualHost localhost:80>
ProxyPass /app2 http://localhost:5001/app2
ProxyPassReverse /app2 http://localhost:5001/app2
<Location />
#Options FollowSymLinks
AllowOverride All
Require all granted
</Location>
</VirtualHost>
When I tried to access localhost/app1, I am getting successfully, but when I tried to access localhost/app2 I am getting Not Found
When I do interchange the first virtualhost with the second and second with the first I am able to access first virtual host only.
Please help me to configure two different virtualhost
You need to use a unique ServerName in each virtualHost. even you can access both applications through a single Virtualhost. i.e
<VirtualHost localhost:80>
ProxyPass /app1 http://localhost:5002/app1
ProxyPassReverse /app1 http://localhost:5002/app1
ProxyPass /app2 http://localhost:5001/app2
ProxyPassReverse /app2 http://localhost:5001/app2
<Location />
#Options FollowSymLinks
AllowOverride All
Require all granted
</Location>
</VirtualHost>

Apache reverse proxy to serve node

I want to setup reverse proxy so http://www.carolinatransparency.com/form is used to serve my node app that is running on http://localhost.com:5000.
The problem is that there seems to be some sort of collision because the .conf file for carolinatransparency.com also handles the /form route and doesn't allow the reverse proxy. Is there a way to disable this specific path in carolinatransparency.com.conf
ServerName www.carolinatransparency.com
ServerAlias carolinatransparency.com
ServerAdmin yasin#generatedesign.com
DocumentRoot /var/www/carolinatransparency.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
form.votetracker.com.conf
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass /form http://localhost:5000
ProxyPassReverse /form http://localhost:5000
ServerName http://www.carolinatransparency.com/form/
</VirtualHost>

The request message was malformed :: Error creating new authz :: DNS name does not have enough labels

I'm trying to setup SSL/HTTPS with certbot, but I'm getting this error:
The request message was malformed :: Error creating new authz :: DNS name does not have enough labels
I'm using Apache2 and this is my virtual host.conf:
<VirtualHost *:80>
<Directory /var/www/html/domain>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/domain
ServerName domain.com.br
ServerAlias www.domain.com.br
ProxyRequests On
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
<Location />
ProxyPass http://localhost:3010/
ProxyPassReverse http://localhost:3010
</Location>
ErrorLog ${APACHE_LOG_DIR}/domain.log
CustomLog ${APACHE_LOG_DIR}/domain.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName domain.com.br
Redirect permanent / http://www.domain.com.br/
</VirtualHost>
How can I fix this?

How to configure apache with proxy_mod for domains redirect

I have a server with only one IP adress but a lot of domain (and sub-doman) but every domain have dedicated virtual machine on my Host Server.
I try to use mod_proxy for ProxyPass and Reverse request and, in apache conf i make it:
<VirtualHost *:80>
ServerAlias mydomain.domain.com
ProxyRequests Off
<Proxy />
Order deny,allow
Allow from all
ProxyPass http://192.168.1.8/
ProxyPassReverse http://192.168.1.8/
</Proxy>
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
ErrorLog ${APACHE_LOG_DIR}/error.log
</VirtualHost>
<VirtualHost *:80>
ProxyRequests Off
ServerAlias domain.domain2.org
ServerAlias subdomanin.domain.com
DocumentRoot /var/www
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
ErrorLog ${APACHE_LOG_DIR}/error.log
</VirtualHost>
In this conf:
domain.domain1.com -> go to 192.168.1.8
subdomanin.domain1.com and another domain -> go to document root.
With ProxyRequests On and "Allow from All" (this conf), apache is an openproxy...
With this config (and ProxyRequest Off), if someone request "www.google.it" with proxy mydomain.domain.com he don't have google but server redirect it to myNumericIp
What is right config for do if http://mydomain.domain.com/some request are redirect to myNumericIp with url http://my.Numeric.Ip/some otherwhise proxy don't response anything).
I try this:
<Proxy http://mydomain.domain.com/>
Order deny,allow
Allow from all
ProxyPass http://192.168.1.8/
ProxyPassReverse http://192.168.1.8/
</Proxy>
Or this:
<Proxy />
Order deny,allow
Allow from all
ProxyPass http://192.168.1.8/
ProxyPassReverse http://192.168.1.8/
</Proxy>
<Proxy *>
Order deny,allow
Deny from all
</Proxy>
But don't work...
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>
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

Apache and tomcat in the same Virtualhost

I have a virtualhost that looks like :
<VirtualHost *:80>
ServerName www.mysite.com
SetOutputFilter DEFLATE
RedirectMatch ^/manager$ http://www.fna.fi/manager/
DocumentRoot /build/vhosts/mysite.com
ErrorLog /build/logs/site.com-error.log
CustomLog /build/logs/site.com-access.log combined
ProxyRequests Off
RewriteEngine on
ProxyPass /manager http://127.0.0.1:8060/manager/ retry=0
ProxyPassReverse /manager http://127.0.0.1:8060/manager
ProxyPass / http://127.0.0.1:8060/app/ retry=0
ProxyPassReverse / http://127.0.0.1:8060/app/
</VirtualHost>
Now I want to add a blog in /build/vhosts/mysite.com. So it will be : http://www.mysite.com/blog but when I access this site it looks like its being forwarded to Tomcat (most likely due to the "ProxyPass /...".
Is there a way to make it work for the scenario I have?
Thanks!
Currently anything will be forwarded to the tomcat:
ProxyPass / http://127.0.0.1:8060/app/ retry=0
ProxyPassReverse / http://127.0.0.1:8060/app/
You have to add a alias before your proxy directives to your config:
Alias /blog /build/vhosts/mysite.com
<Location /blog>
# make some configs for this location like...
Options FollowSymLinks
AllowOverride None
</Location>