Affichage des articles dont le libellé est apache. Afficher tous les articles
Affichage des articles dont le libellé est apache. Afficher tous les articles

vendredi 21 septembre 2018

Redirect HTTP to HTTPS using Apache and Google Cloud Platform Loadbalancer


Using Apache to redirect HTTP to HTTP, if https version of the site is not configured via Apache ModSSL it doesn't set %{HTTPS} variable to "on" and keeps redirecting infinitely.

The best way to do is to send X-Forwarded-Proto header from load balancer to Apache and configure RewriteCond as follow.

If not already done enablerewrite and ssl

a2enmod rewrite
a2enmod ssl
Then in HTTP vhost configure

<VirtualHost *:80>
....

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L,R=301]

...

</VirtualHost>

Instead of the common usage :


RewriteCond %{HTTPS} off

source : https://stackoverflow.com/a/19722706


 

jeudi 22 décembre 2011

Apache reverse proxy

Une petite config de Apache comme reverse proxy pour permettre de faire tourner plusieurs sites sur la meme ip sur le meme port.

NameVirtualHost *:80
<VirtualHost *:80>
    ServerName aa.bbb.com
    ServerAlias aaname.bbname.com
    ErrorLog logs/aaa.com.-error_log
    CustomLog logs/aaa.com.co-access_log common
    ProxyPass / http://192.168.1.118/
    ProxyPassReverse / http://192.168.1.118/
</VirtualHost>

 Attention tout de meme, si vous avez un premier site de configurer, disons statique et que vous creer maintenant un virtualhost vous nous pourrez plus acceder au site static. Il faut declarer chacun comme Virtualhost

NameVirtualHost *:80
Le premier site, "static"
<VirtualHost *:80>
        ServerName www.blabla.com
        ServerAlias blabla.com
        DocumentRoot "/var/www/html"
</VirtualHost>
Le second site, le site virtuel qui renvoit vers une autre machine
<VirtualHost *:80>
    ServerName ohohoho.com
    ServerAlias ohohohoh.com
    ErrorLog logs/ohohohoh.com-error.log
    CustomLog logs/ohohohoh.com-access_log common
    ProxyPass / http://192.168.1.121/
    ProxyPassReverse / http://192.168.1.121/
</VirtualHost>