Bonjour,

Nous somme en train de configurer un serveur (avec un load balancer et cache)
Pound -> Varnish -> Apache -> CentOS.

Nous utilisons X-Forwarded-Proto pour transmettre l'information que nous somme
en https ou niveau en dessous de Pound.

Cela marche bien quand on accède directement une page comme https://example.com. Par contre, quand on accède une page comme http://example.com et que nous faisons une redirection vers https via PHP ou htaccess cela ne fonctionne pas. Nous avons alors une boucle de redirections.

Nous avons une solution qui fonctionne lorsque nous faisons la redirection en Javascript mais nous préférerions avoir une solution coté serveur.

Voici à quoi ressemble nos config:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
///////////////
// htaccess
////////////////////
  RewriteCond %{HTTP:X-Forwarded-Proto} !https
  RewriteRule (.*) https://example.com [L,R]
 
 
///////////////////
// php 
//////////////////
if(isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https'){
	$_SERVER['HTTPS']='on';	
}
 
if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on'){
	header('Location: '. 'https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
}
 
//////////////
//  pound config
//////////
User "pound"
Group "pound"
Control "/path/to/pound.cfg"
 
 
ListenHTTP
    Address 0.0.0.0
    Port 80
      HeadRemove "X-Forwarded-Proto"
      HeadRemove "X-Forwarded-For"
      AddHeader "X-Forwarded-Proto: http"
      RewriteLocation 2
End
 
ListenHTTPS
    Address 0.0.0.0
    Port    443
    Cert    "/path/to/pound.pem"
      HeadRemove "X-Forwarded-Proto"
      HeadRemove "X-Forwarded-For"
      AddHeader "X-Forwarded-Proto: https"
End
 
Service
    BackEnd
            Address 0.0.0.0
        Port    80
    End
 
End


Dans PHP, si je place

header("Location: https://example.com")

dans la réponse je vois:

HTTP/1.1 302 Found
Server: Apache
X-Powered-By: PHP/5.3 ZendServer/5.0
Location: http://example.com
Content-Type: text/html; charset=UTF-8
Content-Length: 0
Accept-Ranges: bytes
Date: Wed, 23 Jan 2013 04:58:22 GMT
X-Varnish: 1294094576
Age: 0
Via: 1.1 varnish
Connection: keep-alive

Donc le https est remplacer par http

J'ai cherché et posté sur plusieurs forums mais personne n'a encore trouver de solution.

Merci.