Bonjour, je suis content de tomber sur un post qui parle de ce problème de reverse proxy (et surtout heureux de constater qu'il y en a qui maîtrise ! Merci Mac). Désolé ça va être un peu long mais je préfère tout de suite poster l'ensemble des informations composant mon problème. Je ne suis pas du genre à réclamer de l'aide avant d'avoir épuisé toutes mes ressources mais malheureusement c'est le cas aujourd'hui.
A votre bon coeur !
Etat actuel de ma configuration:
Une adresse IP fixe publique.
Un serveur sous Linux, Apache 2.2.8 pour le web assurant aussi les services DNS (connu de Registry par glue, donc DNS internet et pas seulement local sur le LAN), SSH, PostFix (Bref la complète jambon-beurre)
DNS a autorité sur toutes les zones utilisées dans l'hébergement des domaines utilisés
Plusieurs sites internet sont hébergés sur ce serveur, ces sites ont été configurés VH dans Apache comme il se doit.
Aucun problème de ce côté là, tout fonctionne depuis des années.
PROBLEME
***************
J'ai besoin d'un second serveur web derrière cette unique IP publique.
Au travers des forums je vois que la solution du reverse proxy a l'air d'être la solution la plus simple pour répondre au problème.
Bien entendu, je tente d'ajouter dans httpd.conf tout ce qui a pu être écrit sur la question afin de forwarder vers l'adresse LAN du second serveur, notamment en appliquant les directives ProxyPass et ProxyPassReverse.
Depuis 2 jours je suis là-dessus à faire mille tests sans succès, la seconde machine a l'air injoignable.
Les vérifications faites
**************************
apache_mod_proxy (RPM) OK
proxy_module: loadé
proxy_connect_module: loadé
proxy_http_module: loadé
mod_rewrite (si besoin): loadé
De toute façon voici ce que phpinfo rapporte sur l'environnement Apache, témoin de ces chargements:
************************************************************
core prefork http_core mod_so mod_authn_file mod_authn_anon mod_authn_default mod_authn_alias mod_authz_host mod_authz_groupfile mod_authz_user mod_authz_dbm mod_authz_owner mod_authz_default mod_auth_basic mod_auth_digest mod_include mod_filter mod_substitute mod_log_config mod_env mod_mime_magic mod_expires mod_headers mod_usertrack mod_unique_id mod_setenvif mod_version mod_mime mod_status mod_autoindex mod_info mod_cgi mod_vhost_alias mod_negotiation mod_dir mod_imagemap mod_actions mod_alias mod_rewrite mod_proxy mod_proxy_connect mod_proxy_http mod_proxy_balancer mod_ssl mod_cache mod_disk_cache mod_userdir mod_suexec mod_php5 mod_perl
************************************************************
DONC, normalement, côté modules proxy tout est là pour mettre les bonnes directives dont on a besoin dans httpd.conf pour faire du reverse mais c'était la moindre des choses de vérifier ...
Poursuivons:
Mac dit à un moment donné que la première ligne de l'un de ses posts est très impostante:
S'agit-il de NameVirtualHost * ? Parce que si tel est le cas, personnellement j'ai une erreur au démarrage de httpd quand j'utilise cette ligne dans la section NameVirtualHost.
Message: Starting httpd: [Fri Jan 16 11:25:22 2009] [error] VirtualHost _default_:443 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results
Donc je n'utilise pas NameVirtualHost *
Voici maintenant mon fichier httpd.conf simplifié, les différents tests infructueux effectués sont dans la section VH. J'ai ôté pas mal de choses dans le cadre de ce post, notamment tous les VH pointant un DocumentRoot ne faisant pas l'objet du problème.
****************************************************
......... c'est dans le include ci-dessus qu'apache va chercher les modules du RPM apache_mod_proxy, j'inclus le fichier de config
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 ServerRoot "/etc/httpd" Listen 192.168.1.61:80 ### INCLUSION DES FICHIERS DE CONFIG COMPLEMENTAIRES - IMPORTANT Include modules.d/*.conf
correspondant ci-dessous:
********* configuration du module proxy ******************
********* fin de configuration du module proxy ******************
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112 <IfDefine HAVE_PROXY> <IfModule !mod_proxy.c> LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_connect_module modules/mod_proxy_connect.so #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule proxy_balancer_module modules/mod_proxy_balancer.so </IfModule> </IfDefine> <IfModule mod_proxy.c> # <Proxy> - Container for directives affecting resources located in the proxied location <Proxy *> Order deny,allow Deny from all # Allow from .your-domain.com </Proxy> # <ProxyMatch> - Container for directives affecting resources located in the proxied location, in regular expression syntax # ProxyRequests - on if the true proxy requests should be accepted ProxyRequests On # ProxyRemote - a scheme, partial URL or '*' and a proxy server #ProxyRemote * <a href="http://firewall.mycompany.com:81" target="_blank">http://firewall.mycompany.com:81</a> #ProxyRemote <a href="http://goodguys.com/" target="_blank">http://goodguys.com/</a> <a href="http://mirrorguys.com:8000" target="_blank">http://mirrorguys.com:8000</a> #ProxyRemote * <a href="http://cleversite.com" target="_blank">http://cleversite.com</a> #ProxyRemote ftp <a href="http://ftpproxy.mydomain.com:8080" target="_blank">http://ftpproxy.mydomain.com:8080</a> # Ne fonctionne pas : ProxyRemote <a href="http://gratuit.troiw.com/" target="_blank">http://gratuit.troiw.com/</a> <a href="http://192.168.1.65/test/" target="_blank">http://192.168.1.65/test/</a> # ProxyRemoteMatch - a regex pattern and a proxy server #ProxyRemoteMatch ... # ProxyPass - a virtual path and a URL # ProxyPass /mirror/foo/ <a href="http://backend.example.com/" target="_blank">http://backend.example.com/</a> # Ne fonctionne pas : ProxyPass <a href="http://gratuit.troiw.com/" target="_blank">http://gratuit.troiw.com/</a> <a href="http://192.168.1.65/test/" target="_blank">http://192.168.1.65/test/</a> # ProxyPassReverse - a virtual path and a URL for reverse proxy behaviour # ProxyPassReverse /mirror/foo/ <a href="http://backend.example.com/" target="_blank">http://backend.example.com/</a> # Ne fonctionne pas : ProxyPassReverse <a href="http://gratuit.troiw.com/" target="_blank">http://gratuit.troiw.com/</a> <a href="http://192.168.1.65/test/" target="_blank">http://192.168.1.65/test/</a> # ProxyPassReverseCookiePath - Path rewrite rule for proxying cookies #ProxyPassReverseCookiePath / /mirror/foo/ # ProxyPassReverseCookieDomain - Domain rewrite rule for proxying cookies #ProxyPassReverseCookieDomain backend.example.com public.example.com # ProxyBlock - A list of names, hosts or domains to which the proxy will not connect #ProxyBlock joes-garage.com some-host.co.uk rocky.wotsamattau.edu # ProxyReceiveBufferSize - Receive buffer size for outgoing HTTP and FTP connections in bytes ProxyReceiveBufferSize 0 # ProxyIOBufferSize - IO buffer size for outgoing HTTP and FTP connections in bytes ProxyIOBufferSize 8192 # ProxyMaxForwards - The maximum number of proxies a request may be forwarded through. ProxyMaxForwards 10 # NoProxy - A list of domains, hosts, or subnets to which the proxy will connect directly #NoProxy .mycompany.com 192.168.112.0/21 # ProxyDomain - The default intranet domain name (in absence of a domain in the URL) #ProxyDomain .mycompany.com # AllowCONNECT - A list of ports which CONNECT may connect to # AllowCONNECT 443 563 # ProxyVia - Configure Via: proxy header header to one of: on | off | block | full ProxyVia On # ProxyErrorOverride - use our error handling pages instead of the servers' we are proxying ProxyErrorOverride Off # ProxyPreserveHost - on if we should preserve host header while proxying ProxyPreserveHost Off # ProxyTimeout - Set the timeout (in seconds) for a proxied connection. This overrides the server timeout ProxyTimeout 300 # ProxyBadHeader - How to handle bad header line in response: IsError | Ignore | StartBody ProxyBadHeader IsError # BalancerMember - A balancer name and scheme with list of params #ProxyPass /special-area <a href="http://special.example.com/" target="_blank">http://special.example.com/</a> smax=5 max=10 #ProxyPass / balancer://mycluster stickysession=jsessionid nofailover=On #<Proxy balancer://mycluster> #BalancerMember <a href="http://1.2.3.4:8009" target="_blank">http://1.2.3.4:8009</a> #BalancerMember <a href="http://1.2.3.5:8009" target="_blank">http://1.2.3.5:8009</a> smax=10 # Less powerful server, don't send as many requests there #BalancerMember <a href="http://1.2.3.6:8009" target="_blank">http://1.2.3.6:8009</a> smax=1 loadfactor=20 #</Proxy> # ProxyStatus - Configure Status: proxy status to one of: on | off | full #ProxyStatus full # ProxySet - A balancer or worker name with list of params #ProxySet ? </IfModule> <IfModule mod_proxy_balancer.c> <Location /balancer-manager> SetHandler balancer-manager Order Deny,Allow Deny from all #Allow from .foo.com </Location> </IfModule>
... Voilà, toutes mes infos sont là.
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69 Include conf.d/*.conf User apache Group apache ServerAdmin root@localhost TimeOut 300 KeepAlive on MaxKeepAliveRequests 100 KeepAliveTimeout 5 UseCanonicalName Off ServerTokens Prod ServerSignature Off HostnameLookups Off DocumentRoot /var/www/html AccessFileName .htaccess DefaultType text/plain ErrorLog logs/error_log LogLevel warn ### Section 3: Virtual Hosts NameVirtualHost 192.168.1.61:80 NameVirtualHost 192.168.1.61:443 Include conf/vhosts.d/*.conf <VirtualHost 192.168.1.61:80> DocumentRoot "/home/www/exemple" ServerName <a href="http://www.trucbidule.com" target="_blank">www.trucbidule.com</a> <Directory "/home/www/exemple"> allow from all Options +Indexes </Directory> </VirtualHost> # DEBUT TEST FORME 1 DE REVERSE PROXY # <VirtualHost *> # ProxyRequests off # ServerName <a href="http://www.essai.com" target="_blank">www.essai.com</a> # <Proxy *> # Order allow,deny # Allow from all # </Proxy> # <Location /> # ProxyPass <a href="http://192.168.1.65/" target="_blank">http://192.168.1.65/</a> # ProxyPassReverse <a href="http://192.168.1.65/" target="_blank">http://192.168.1.65/</a> # Allow From All # </Location> # </VirtualHost> # FIN TEST DE PROXY REVERSE # DEBUT TEST FORME 2 DE REVERSE PROXY # <VirtualHost www.essai.com> # ServerName <a href="http://www.essai.com" target="_blank">www.essai.com</a> # RewriteEngine On # RewriteRule ^/(.*) \http://192.168.1.65:80/$1 [P] # </VirtualHost> # FIN TEST DE PROXY REVERSE # DEBUT TEST FORME 3 DE REVERSE PROXY <VirtualHost *> ProxyRequests off ServerName <a href="http://www.essai.com" target="_blank">www.essai.com</a> <Proxy *> Order allow,deny Allow from all </Proxy> ProxyPass / <a href="http://192.168.1.65/" target="_blank">http://192.168.1.65/</a> ProxyPassReverse / <a href="http://192.168.1.65/" target="_blank">http://192.168.1.65/</a> </VirtualHost> # FIN TEST DE PROXY REVERSE
Jamais www.essai.com n'aura été redirigé vers le second serveur 192.168.1.65 par aucune des formes de directives utilisées.
Pour info, dans le fichier de conf des modules proxy, tout ce qui était à off a été mis à on pour tenter le coup (exemple ProxyPreserveHost on évoqué dans l'un des posts ci-dessus).
Pour terminer: tout ce qui pouvait toucher de près ou de loin aux firewalls a été désactivé pour éviter d'avoir un problème à ce niveau.
Qu'est-ce qui m'échappe au vu de toutes ces données ?
Un grand merci d'avance aux courageux qui auront la patience de tout lire ...
Philippe
Partager