Hosted Private Cloud OVHcloud - [HAProxy] Problème de redirection backend
BMPCreated with Sketch.BMPZIPCreated with Sketch.ZIPXLSCreated with Sketch.XLSTXTCreated with Sketch.TXTPPTCreated with Sketch.PPTPNGCreated with Sketch.PNGPDFCreated with Sketch.PDFJPGCreated with Sketch.JPGGIFCreated with Sketch.GIFDOCCreated with Sketch.DOC Error Created with Sketch.
Frage

[HAProxy] Problème de redirection backend

Von
JovanyG
Erstellungsdatum 2020-02-06 08:46:40 (edited on 2024-09-04 13:02:46) in Hosted Private Cloud OVHcloud

Bonjour,

J'ai un dédié chez OVH afin de mettre en place ma plateforme.

Les VMs en interne sont prêtes à être exploité. Afin de faire le reverse proxy, j'ai choisi de prendre HAProxy.

Cependant sur mon 1er frontend / backend, j'ai ce message :
> La page n’est pas redirigée correctement

Voici ma configuration HAProxy :

> global
> log 127.0.0.1 local0 debug
> log /dev/log local0 notice
> maxconn 1024
> chroot /var/haproxy
> uid 604
> gid 604
> daemon
> stats socket /var/run/haproxy.sock mode 666 level admin
> pidfile /var/run/haproxy.pid
> ssl-default-bind-ciphers ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:ECDHE-ECDSA-DES-CBC3-SHA:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-CHACHA20-POLY1305-D:TLS_DHE_RSA_WITH_CAMELLIA_128_CBC_SHA256:TLS_DHE_RSA_WITH_CAMELLIA_256_CBC_SHA256:TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256:TLS_RSA_WITH_CAMELLIA_128_CBC_SHA256:TLS_RSA_WITH_CAMELLIA_256_CBC_SHA256:!DSS
> ssl-default-bind-options no-tlsv11 no-sslv3 no-tlsv10 no-tls-tickets
> tune.ssl.default-dh-param 2048
> tune.maxrewrite 16384
> tune.bufsize 65535

> defaults
> log global
> mode http
> option redispatch
> option forwardfor
> retries 3
> maxconn 2000
> timeout server 60s
> timeout connect 5s
> timeout client 10s
> log-format "%ci [%tr] %ft %b/%s %TR/%Tw/%Tc/%Tr/%Ta %ST %B %CC %CS %tsc %ac/%fc/%bc/%sc/%rc %sq/%bq %hr %hs %{+Q}r"

> frontend http-s-storage-domain-name

> bind *:80
> bind *:443 ssl crt /etc/haproxy/ssl/storage.domain-name.com.haproxy.pem no-sslv3
> mode http
> option httplog clf
> option forwardfor
> option http-keep-alive

> capture request header Host len 64
> capture request header Referer len 128
> capture request header User-Agent len 128
> capture request header X-Hit-Front len 128

> #timeout server 60s
> #timeout connect 5s

> acl letsencrypt-acl path_beg /.well-known/acme-challenge/
> #www to non-www
> #acl has_www hdr_beg(host) -i www
> acl storage-domain hdr(host) -i storage.domain-name.com


> # HTTP->HTTPS
> #http-request redirect code 301 prefix https://%[req.hdr(Host)] unless { ssl_fc }

> #http-request redirect scheme https if !{ ssl_fc }
> #http-request add-header X-Forwarded-Proto https if { ssl_fc }
> #http-request add-header X-Forwarded-Proto http unless { ssl_fc }

> #http-request redirect prefix https://www.%[hdr(host)] code 302 if storage-domain !has_www

> use_backend letsencrypt-backend if letsencrypt-acl

> use_backend nextcloud-storage-domain-name if storage-domain

> backend nextcloud-storage-domain-name

> default-server inter 4s
> timeout server 2h
> http-check expect status 200
> #redirect scheme https code 301 if !{ ssl_fc }
> server nextcloud 172.16.X.X:8080 cookie A check port 8080 fall 5 rise 3

> backend letsencrypt-backend
> server letsencrypt 127.0.0.1:1375 check

Configuration apache2 sur ma VM :


ServerName nextcloud.domain-name.com
ServerAlias storage.domain-name.com

ServerAdmin contact@domain-name.com
DocumentRoot /data-nextcloud/web/nextcloud

#regle htaccess

Order allow,deny
Deny from all


#regle log apache2

Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from all
Require all granted


ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

#set home for nextcloud


Options +FollowSymlinks
AllowOverride All
Require all granted

Dav off


SetEnv HOME /data-nextcloud/web/nextcloud
SetEnv HTTP_HOME /data-nextcloud/web/nextcloud


#redirect to https
RewriteEngine on
RewriteCond %{SERVER_NAME} =storage.domain-name.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]





SSLEngine on
SSLOptions +StrictRequire
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" vhost_combined
LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common
ServerAdmin contact@domain-name.com
DocumentRoot /data-nextcloud/web/nextcloud
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName nextcloud.domain-name.com
ServerAlias storage.domain-name.com

SSLCertificateFile /etc/apache2/ssl/storage.domain-name.com.cer
SSLCACertificateFile /etc/apache2/ssl/storage.domain-name.com.haproxy.pem
SSLCertificateKeyFile /etc/apache2/ssl/storage.domain-name.com.key


Options +FollowSymlinks
AllowOverride All
Require all granted

Dav off

SetEnv HOME /data-nextcloud/web/nextcloud
SetEnv HTTP_HOME /data-nextcloud/web/nextcloud


Header always set Strict-Transport-Security "max-age=15768000; preload"
Header set Referrer-Policy "strict-origin-when-cross-origin"
Header set X-Content-Type-Options "nosniff"
#Header always set X-Frame-Options "SAMEORIGIN"


SSLProtocol -all +TLSv1.3 +TLSv1.2
SSLCipherSuite TLS-CHACHA20-POLY1305-SHA256:TLS-AES-256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384
SSLHonorCipherOrder on
SSLCompression off
SSLSessionTickets off
SSLUseStapling on
SSLStaplingResponderTimeout 5
SSLStaplingReturnResponderErrors off
SSLStaplingCache shmcb:/var/run/ocsp(128000)
SSLOpenSSLConfCmd Curves X448:secp521r1:secp384r1:prime256v1
SSLOpenSSLConfCmd ECDHParameters secp384r1
SSLOpenSSLConfCmd DHParameters "/etc/ssl/certs/dhparam.pem"


Avez-vous des axes d'amélioration à me proposer ?

Je suis dans l'amélioration continue,

En vous remerciant par avance,


3 Antworten ( Latest reply on 2020-02-06 17:43:24 Von
janus57
)

tu devrais **éditer** le titre de ton sujet et choisir la catégorie : Cloud / Dédié
tu auras des réponses adaptées

Bonjour,

J'ai pas regardé en détails la configuration HAProxy mais au niveau de apache il faut retirer la redirection HTTPS si la redirection est faite sur HAProxy.

Si vous voulez faire la redirection au niveau de apache il faut :
Dans le frontend qui gère https ajouter [code]http-request set-header X-Forwarded-Proto https[/code]
Puis côté apache le RewriteCond doit se baser dessus [code]RewriteCond %{HTTP:X-Forwarded-Proto} =http[/code]

Note : je vous conseil de faire 2 frontend : 1 pour http et un autre pour https

Cordialement, janus57

Merci !

C'est bien côté apache2 qui faisait une "boucle"

D'autres conseils ?

Bonjour,

Si tout doit être en https perso je fait la redirection dans HAProxy et ne fait rien au niveau des backends pour la redirection.

Ce qui permet aussi de filtrer au niveau de HAProxy via des ACL (par exemple je redirige que certains sites de http vers https et d'autres 0 redirections il faut directement arriver en https sinon HAProxy renvoie une erreur 503)

Cordialement, janus57