How to configure apache with proxy_mod for domains redirect - apache

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

Related

Apache serve service from local host on subdomain

I am trying to use Apache to serve multiple sites at the same time, the structure I want to obtain is composed by a main site at example.com and use the subdomains radarr.example.com and sonarr.example.com to access my Radarr and Sonarr servers.
The main site is hosted on machine1, I set up a virtual host using apache and certbot:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName example.com
WSGIDaemonProcess sflasksite user=www-data group=www-data threads=5
WSGIScriptAlias / /var/www/webapp/app.wsgi
<Directory /var/www/webapp>
WSGIProcessGroup sflasksite
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Require all granted
</Directory>
Alias /static /var/www/webapp/static
<Directory /var/www/webapp/static/>
Order deny,allow
Require all granted
</Directory>
ErrorLog /var/www/webapp/logs/error.log
CustomLog /var/www/webapp/logs/access.log combined
SSLCertificateFile /etc/letsencrypt/live/example.com-0002/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com-0002/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
The two servers I want to serve are on machine2, on the same network as machine1, how can I obtain the two services respectively on radarr.example.com and sonarr.example.com?
After some reading, I tried to use a Reverse Proxy, configuring a virtual host for each service as follows:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerAlias radarr.example.com
ProxyPass / http://192.168.1.20:7878/
ProxyPassReverse / http://192.168.1.20:7878/
ErrorLog /var/www/radarr/logs/error.log
CustomLog /var/www/radarr/logs/access.log combined
</VirtualHost>
and alike for Sonarr.
However, when I navigate to radarr.example.com, I do not get the expected service but the main site.
How can I get the reverse proxy to work? Or should I switch to another strategy altogether?

Apache proxy/redirect to Tomcat works from 80 to 8080 but not from 443 to 8443

In my Apache configuration I have two virtual server setups, one for 80 and one for 443. My VirtualHost *:80 config successfully proxies/redirects a path to tomcat 8080, but my analogously configured VirtualHost *:443 config is not proxying to the required tomcat 8443.
I have checked the Connector in tomcat and can successfully hit the tomcat endpoints directly over 8443. I can also hit other parts of the web-server over 443, just not any of the app-server endpoints that require the proxy/redirect. So, I know that the certs and tomcat configs are working.
Apache and Tomcat are running on the same ec2 server.
<VirtualHost *:80>
ServerName cloviscorp.com
DocumentRoot /var/www/html/com/cloviscorp
<Directory "/var/www/html/com/cloviscorp">
Order Allow,Deny
Allow From All
AllowOverride All
Options -Indexes
</Directory>
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost On
ProxyPass /ClovisWebApp http://localhost:8080/ClovisWebApp
ProxyPassReverse / http://localhost:8080/
... (CORS config and LOG setup) ...
</VirtualHost>
<VirtualHost *:443>
ServerName cloviscorp.com
DocumentRoot /var/www/html/com/cloviscorp
<Directory "/var/www/html/com/cloviscorp">
Order Allow,Deny
Allow From All
AllowOverride All
Options -Indexes
</Directory>
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPreserveHost On
ProxyPass /ClovisWebApp https://localhost:8443/ClovisWebApp
ProxyPassReverse / https://localhost:8443/
SSLEngine on
SSLCertificateFile "/etc/httpd/server.crt"
SSLCertificateKeyFile "/etc/httpd/server.key"
... (CORS config and LOG setup) ...
</VirtualHost>
When hitting http://www.cloviscorp.com/ClovisWebApp/authenticationservice/login I correctly proxy to http://www.cloviscorp.com:8080/ClovisWebApp/authenticationservice/login, but when I hit https://www.cloviscorp.com/ClovisWebApp/authenticationservice/login I get The requested URL /ClovisWebApp/authenticationservice/login was not found on this server.

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

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

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.

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