My customer accountContact commercialWebmailOVHcloud Blog

Welcome to OVHcloud.

Log in to order, manage your products and services, and track your orders

Log in

OVH Load Balancer : HTTP Header

Get HTTP Headers on your services behind OVH Load Balancer

Introduction

With any frontend service like CDN, IP Loadbalancing in front of your services, the IP of your clients is hidden by this service.

In your log, you'll only see privateIP, and we'll fix this.

10.108.0.15 - - [22/Mar/2017:10:56:47 +0100] "GET / HTTP/1.1" 200 706 "-" "Mozilla/5.0 (Linux[...]"
10.108.0.24 - - [22/Mar/2017:10:56:47 +0100] "GET / HTTP/1.1" 200 706 "-" "Mozilla/5.0 (Linux[...]"

Warning

You need to restrict access to your webservices from our IP Loadbalancing.

With this api call you can get IP Range of our servers.

Headers

X-Forwarded-For

This header have inside the Ip of your client.

Apache

1. LogFormat "%{X-Forwarded-For}i-%h- %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" loadbalancing
2. CustomLog /chemin/fichier.log loadbalancing

Nginx

1. log_format "%{X-Forwarded-For}i-%h- %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" loadbalancing
2. access_log /chemin/fichier.log loadbalancing

X-Forwarded-Proto

You can also get the scheme used by your client to reach OVH Load Balancer. This is helpfull to redirect HTTP to HTTPS

Apache

With htaccess, you can redirect your customers in HTTPS.

1. RewriteEngine on
2. RewriteCond %{HTTP:X_Forwarded_Proto} !https
3. RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Nginx

This is not a good configuration, you'll reduce your service performance.

if ($http_x_forwarded_proto = "http") {
        return 301 https://$host/$request_uri;
}

Nginx (best)

With Nginx, it's best to use a entire VHost to redirect HTTP to HTTPS.

server {
        listen [::]:80 default_server;
        listen 80 default_server;
        server_name _;
        root /var/www/;
        location / {
                return 301 https://$server_name$request_uri;
        }
}

Send headers to PHP

Apache

1. Header set REMOTE_ADDR %{HTTP:X_Forwarded_Proto}

Nginx

With RealIP module.

1. real_ip_header X-Forwarded-For;
2. set_real_ip_from 10.108.0.0/16;

Did you find this guide useful?

Please feel free to give any suggestions in order to improve this documentation.

Whether your feedback is about images, content, or structure, please share it, so that we can improve it together.

Your support requests will not be processed via this form. To do this, please use the "Create a ticket" form.

Thank you. Your feedback has been received.

OVHcloud Community

Access your community space. Ask questions, search for information, post content, and interact with other OVHcloud Community members.

Discuss with the OVHcloud community

In accordance with the 2006/112/CE Directive, modified on 01/01/2015, prices incl. VAT may vary according to the customer's country of residence
(by default, the prices displayed are inclusive of the UK VAT in force).