Domain redirected you too many times - apache

I have an Apache web server.
I would like to setup a reverse proxy to access a local application running on port 9090.
Here is my apache configuration :
ProxyRequests Off
NameVirtualHost *:80
NameVirtualHost *:443
SSLProtocol ALL -SSLv2 -SSLv3
SSLHonorCipherOrder On
SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:AES:CAMELLIA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!aECDH:!EDH-DSS-DES-CBC3-SHA:!EDH-RSA-DES-CBC3-SHA:!KRB5-DES-CBC3-SHA
# Redirect HTTP requests to HTTPS
<VirtualHost *:80>
DocumentRoot "${SRVROOT}/htdocs/example.com/public_html"
ServerName example.com
ServerAlias example
Redirect / https://www.example.com/
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "${SRVROOT}/htdocs/example.com/public_html"
ServerName example.com
ServerAlias example
ProxyPass / http://127.0.0.1:9090/
ProxyPassReverse / http://127.0.0.1:9090/
ProxyPreserveHost On
RequestHeader unset Origin
</VirtualHost>
The configuration is not working. I'm getting the error : example.com redirected you too many times
The server is hosted at an EC2 AWS instance.
Does anyone know how to solve that please ?
Thanks.

Related

Apache - virtual host - proxy - https

I have some servers with http apps. Now i need to secure it with https but i cant do it individualy, all of them is on same public IP.
So i decided to create HTTP Gateway - transparent proxy server. I must run it on Windows Server 2016.
I have installed XAMPP server and letsencrypt-simple. I have successfully requested and installed certificate, but on visit of website it is still make "Too many redirects" (and it is secured by HTTPS), whitout proxy it works well.
My virtualhosts:
<VirtualHost *:80>
ServerName [public_domain_name]
ProxyPreserveHost On
DocumentRoot C:\HTTP\SERVER\htdocs\app1
ProxyPass C:\HTTP\SERVER\htdocs\app1\.well-known !
ProxyPass / http://192.168.1.9/app1/
ProxyPassReverse / http://192.168.1.9/app1/
</VirtualHost>
<VirtualHost *:443>
ServerName [public_domain_name]
ProxyPreserveHost On
DocumentRoot C:\HTTP\SERVER\htdocs\app1
ProxyPass C:\HTTP\SERVER\htdocs\app1\.well-known !
ProxyPass / http://192.168.1.9/app1/
ProxyPassReverse / http://192.168.1.9/app1/
SSLEngine on
SSLCertificateFile "C:\ProgramData\win-acme\httpsacme-v01.api.letsencrypt.org\[public_domain_name]-crt.pem"
SSLCertificateKeyFile "C:\ProgramData\win-acme\httpsacme-v01.api.letsencrypt.org\[public_domain_name]-key.pem"
SSLCertificateChainFile "C:\ProgramData\win-acme\httpsacme-v01.api.letsencrypt.org\ca-[public_domain_name]-crt.pem"
</VirtualHost>

Redirect a virtualhost http & https to another virtualhost server

I have 2 apache 2.4 serverA and serverB with several virtualhost. All incoming requests arrive on serverA.
How do I forward http and https request for a specific virtualhost name from serverA to serverB?
My wamp ServerA setup is:
into my hosts file
127.0.0.7 example.com
The virtualhost:
<VirtualHost *:*>
ServerName example.com
ProxyPreserveHost On
ProxyPass "/" "http://192.168.1.105/"
ProxyPassReverse "/" "http://192.168.1.105/"
</VirtualHost>
My serverB ip is 192.168.1.105 and I setup a virtual host on it with the same name example.com
when I use http://example.com I stay on the wamp home page like http://localhost
and when I use https://example.com I have error 403 (Forbidden) on serverA
After a long night, I find a solution:
<VirtualHost *:80>
ProxyPreserveHost On
ProxyPass "/" "http://192.168.1.105/"
ProxyPassReverse "/" "http://192.168.1.105/"
ServerName example.com
</VirtualHost>
<VirtualHost *:443>
SSLProxyEngine on
SSLCertificateFile "${APACHE_DIR}/conf/ssl_example.com/server.crt"
SSLCertificateKeyFile "${APACHE_DIR}/conf/ssl_example.com/server.key"
ErrorLog "logs/example.com-ssl_error.log"
CustomLog "logs/example.com-ssl_access.log" common
ProxyPreserveHost On
ProxyPass "/" "https://192.168.1.105/"
ProxyPassReverse "/" "https://192.168.1.105/"
ServerName example.com
</VirtualHost>
in ServerA virtualhost add a simple:
Redirect / https://serverb.examample.com/

Virtual host with XAMP and APPSERVER

I have XAMPP and Appserver installed in one server (The first listens port 8080 and the second listens port 80).
I have a domain: example.com
I have this in APPSERV:
<VirtualHost 1.2.3.4:80>
ServerName example.com
DirectoryIndex index.php index.html
DocumentRoot "C:/appserv/www/folder"
</VirtualHost>
Is there a way so I can send that request to port 8080?
Here is a simplified version of how I accomplished it with ProxyPreserveHost
<VirtualHost www.example.com:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.example.com
ServerAlias example.com
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
</VirtualHost>

Redirect http to https by configuring .conf file of apache

I have configure apache to tomcat configuration by code like
<VirtualHost *:80>
ServerName captiveportal
ProxyPass / http://ip:port/path
ProxyPassReverse / http://ip:port/path
</VirtualHost>
Now i want to reirect this request to https
How can i achieve this ?
After looking your answer i have changes my configuration like
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile "/etc/httpd/conf/crt1.crt"
SSLCertificateKeyFile "/etc/httpd/conf/key1.key"
ProxyPass / http://ip:port/path
</VirtualHost>
<VirtualHost *:80>
ServerName captiveportal
Redirect / https://ip:port/path
</VirtualHost>
but when i type captiveportal on my browser it redirects me on url https://ip:port/path and it displays problem loading page
One more thing i don't want to display https://ip:port/path on browser.
Note :- https://ip:port/path where port is my tomcat port and ip is machine ip where tomcat run.
You could do something like this:
<VirtualHost *:80>
ServerName captiveportal
Redirect / https://my.host.name/
</VirtualHost>
...and then put your ProxyPass directives in side your SSL VirtualHost block instead.

Apache - Proxy all subdomains from one IP

I'm trying to handle subdomains on a specific server and the normal URL from all servers. They're behind a load balancer. This works for http://test.com and it load balances.
For subdomains I can't tell if the proxy is working or why I'm getting a 404 error. Is there anything wrong with my config?
DNS: example.com 111.111.111.111
Load Balancer: 111.111.111.111
Master, write server: 222.222.222.222
httpd.conf, mirrored to all servers:
<Directory />
Header add myServerName "anglefish" # add a string for testing which server
Header add myServerTimes "D%D t%t"
</Directory>
000-default mirrored to each server except master
#Proxy subdomains from one server
<VirtualHost *:80>
ServerName *.example.com
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://222.222.222.222/
ProxyPassReverse / http://222.222.222.222/
</VirtualHost>
<VirtualHost *:443>
ServerName *.example.com
SSLEngine on
SSLProxyEngine On
SSLEngine on
SSLCertificateFile /etc/apache2/.ssh/example.com.crt
SSLCertificateKeyFile /etc/apache2/.ssh/example.com.key
SSLCertificateChainFile /etc/apache2/.ssh/example.com_bundle.crt
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://222.222.222.222/
ProxyPassReverse / http://222.222.222.222/
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/vhosts/example.com/public_html
<Directory /var/www/vhosts/example.com/public_html>
Options -Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName example.com
ServerAlias example.com
DocumentRoot /var/www/vhosts/example.com/public_html
SSLEngine on
SSLCertificateFile /etc/apache2/.ssh/example.com.crt
SSLCertificateKeyFile /etc/apache2/.ssh/example.com.key
SSLCertificateChainFile /etc/apache2/.ssh/example.com_bundle.crt
</VirtualHost>