SOLVED: How to configure Apache2 with Reverse Proxy. Map an internal website to a folder of another (public) website on the same server - apache

I have build a SPA and deployed it to my server. It is running on http://my-server:3000.
I then installed Apache2 and created a static page. This website is on the same server http://my-server:80 and is open to the Internet via a My-domain.
What I'm trying to accomplish now is to add a link on this static page (http://my-server/foo) which is redirected to http://my-server:3000 in such a way that the here deployed SPA can be run from this sub-folder.
I configured a new Virtual host in Apache2 with the following configuration:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName My-domain
ProxyRequests Off
ProxyHTMLEnable On
ProxyHTMLExtended Off
ProxyPreserveHost On
ProxyPass /foo/ http://my-server:3000/
<Location /foo/>
ProxyHTMLURLMap / /foo/
ProxyPassReverse http://my-server:3000/
SetOutputFilter INFLATE;DEFLATE
</Location>
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
LogLevel info
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Although the SPA is accessed and all the files are loaded the application will not start due to the error No match for URL in routes. I think it is due to the fact that the SPA is build to run in the root of a website and I'm now trying to run it in a sub-folder.
Does anyone know if this is possible? A solution would be appreciated much :-)
I found a solution which works for me :-)
Since I can use any prefix before My-domain like foo.My-domain, just found out recently, I changed the configuration for my Virtual host to this:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName foo.My-domain
ProxyRequests Off
ProxyHTMLEnable On
ProxyHTMLExtended Off
ProxyPreserveHost On
ProxyPass / http://my-server:3000/
<Location />
ProxyPassReverse http://my-server:3000/
SetOutputFilter INFLATE;DEFLATE
</Location>
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
LogLevel info
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And because my SPA now is allowed to run in the root of a website it is working. :-)

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 as reverse proxy doesn't work

I am trying to publish, behind a proxy, a Spring app (also with Spring Security) which has /x/services as entry point. It is running in Tomcat in 8080 in Google Engine (Debian). I configure Apache 2 as a reverse proxy with next configuration
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ProxyRequests off
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ProxyPreserveHost On
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
# Servers to proxy the connection, or
# List of application servers Usage
ProxyPass / http://127.0.0.1:8080/x/services/
ProxyPassReverse / http://127.0.0.1:8080/x/services
ServerName localizator.org
ServerAlias *.localizator.org
</VirtualHost>
I checked it against a lot of examples and seems it is OK, but the only response I am getting is the "Index of /" page. And Apache logs are not helping at all.
Any help will be very appreciated.
For those with a similar problem don't forget to do :
sudo a2ensite proxy-host
(lets suppose your .conf file name is proxy-host)

Redirect Apache application to dot net core application

I have a server which uses a domain example.com. I am using apache to run this web server. I have also installed Dot Net core and published a Dot Net core app to /var/www/app location.
I a trying to access this application using example.com/api
This below is what I have tried in 000-default.conf
<VirtualHost *:80>
ServerAdmin root#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
the below is what I hvae added for the application
<VirtualHost *:80>
ServerName example.com/api
ProxyPreserveHost On
<Proxy *>
Order allow, deny
Allow from all
</Proxy>
ProxyPass / http://localhost:5000/
ProxyPassReverse / http://localhost:5000/
</VirtualHost>
I have also tried the below configuration.
<VirtualHost *:80>
ServerName example.com/api
redirect / http://localhost:5000/
</VirtualHost>
can someone please help me find what am I doing wrong and how to achieve this properly.
This is solved by enabling proxy and proxy_http using commands below.
a2enmod proxy
a2enmod proxy_http
Also configured the Proxy inside the virtual host as follows.
<VirtualHost *:80>
ServerAdmin root#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/html
#Below 3 lines worked
ProxyPreserveHost On
Proxypass "/api/" "http://localhost:5000/"
ProxyPassReverse "/api/" "http://localhost:5000/"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Setting up reverse proxy using Apache on Windows Server 2008 R2

I am trying to setup Reverse Proxy using Apache Server 2.4.23 for two different domain. One domain is pointing to localhost site and other is pointing to other server web site. Here are my configuration
Listen 111.111.11.222:80
Listen 111.111.11.333:80
<VirtualHost 111.111.11.222:80>
ServerName myapp.com
ErrorLog "logs/app_error_log"
CustomLog "logs/app_access_log" common
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://111.111.11.222:8090/
ProxyPassReverse / http://111.111.11.222:8090/
<Location />
Order allow,deny
Allow from all
</Location>
</VirtualHost>
<VirtualHost 111.111.11.333:80>
ServerName myauditor.com
ProxyRequests Off
# ProxyPreserveHost On
ErrorLog "logs/auditor_error_log"
CustomLog "logs/auditor_access_log" common
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://www.mycompamy.com/
ProxyPassReverse / http://www.mycompany.com/
</VirtualHost>
In these settings, first "myapp.com" is working fine as needed. However when I try myauditor.com then instead of acting it as reverse proxy, it is redirecting to www.mycompany.com.
In myauditor.com setting, if I un-comment and use ProxyPreserveHost On then myauditor.com start giving me error
Invalid URL
The requested URL "http://%5bNo%20Host%5d/", is invalid.
Reference #9.2d3d6b68.1485193636.126886bd
I am new to Apache so I am not sure, when ProxyPreserveHost is working fine in first VirtualHost then why it causing issue in second VirtualHost.

Looking to redirect path /blog to another server using Apache

I want to host my blog on it's own server, but have the URL be at mysite.com/blog
Should I do this using mod_proxy or an apache redirect, and how would I set this up on apache?
My first pass attempt looks like so in the vhost file, but failed:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass /blog http://blog.server's.ip.address/
ProxyPassReverse /blog http://blog.server's.ip.address/
ServerAdmin me#myemail.com
ServerName mysite.com
DocumentRoot /var/www
<Directory /var/www>
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
With this is place I get the following error when restarting apache:
Restarting web server apache2 /sbin/start-stop-daemon: warning: failed to kill 11306: Operation not permitted
[fail]
The apache2 configtest failed, so we are trying to kill it manually. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!
mod_proxy needs to be enabled before working >_<
Once I enabled it my config worked as expected.
a2enmod proxy_http
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass /blog http://server4.hostinger.co.uk.ip.31.170.164.19/
ProxyPassReverse /blog http://server4.hostinger.co.uk.ip.31.170.164.19/
ServerAdmin http://webmail.hostinger.co.uk
ServerName armukul.com.ip address 31.170.164.123 domain ip ("A" DNS record) to this IP: 31.170.164.123
DocumentRoot /var/www.armukul.com/home/u311366417
<Directory /var/www>armukul.com
Order allow,deny
allow from all
</Directory>www>armukul.net
</Directory>www>facebook.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>[][1]
[1]: http://armukul.com/home