Skip to main content

PROXY protocol (real visitor IP on HTTPS)

For domains with Website protection off, HTTPS is passed through to your origin without being decrypted, so the sentry can't add an X-Forwarded-For header (see Trusting the sentry). Without anything else, the origin sees the sentry's address on every HTTPS connection.

PROXY protocol fixes that without turning on Website protection. When it is on for a domain, the sentry starts every HTTPS connection to the origin with a short header that holds the visitor's IP address. A web server that understands PROXY protocol reads that header and uses the visitor's address in its logs, .htaccess rules and PHP (REMOTE_ADDR).

  • It applies to HTTPS (port 443) only. Plain HTTP on port 80 keeps using X-Forwarded-For, so set that up too.
  • domains with Website protection don't need it: they always send X-Forwarded-For.
  • It is off by default.
Set up the origin first

Turn on PROXY protocol for a domain only once its origin web server accepts it on the HTTPS port. Once Apache or nginx expects the header, it rejects HTTPS connections that arrive without it, and a server that doesn't expect it can't read connections that start with one. If the two sides don't match, the site stops loading over HTTPS until they do.

How it works with your control panel​

Web servers turn PROXY protocol on per IP address and port, not per website. Once it is on for the origin's HTTPS port, every site on that IP and port expects the header. So:

  • turn PROXY protocol on in the portal (Domains page) for all domains that use that origin;
  • the Domains page warns you when some domains on an origin have it on and others off.

Because the header carries the visitor address, anyone who can connect straight to the origin's HTTPS port could send a fake one. Allow the origin's HTTPS port only from your sentries in its firewall, or list the sentries as the only trusted sources where your web server supports that (LiteSpeed does).

The installer sets up a version of nginx that supports this.

Turning it on​

  1. Note the public IP addresses of every sentry in the cluster (ip -br addr on each sentry).
  2. Set up the origin's web server using the guide for your panel below.
  3. In the portal, open Domains and click Off in the PROXY column for each domain on that origin, then confirm. If the column shows n/a, Website protection is on for that domain and already sends the visitor IP, so PROXY protocol isn't needed. The sentries pick up the change within about a minute.
  4. Open the site over HTTPS and check the origin's access log or $_SERVER["REMOTE_ADDR"] in PHP. It should show the visitor's address.

With Apache or nginx on the origin, the change on the origin and in the portal should happen as close together as possible. Until both are done, HTTPS for that origin's sites fails. LiteSpeed accepts connections with or without the header, so with LiteSpeed set up the origin first and turn the portal on afterwards, with no gap.

To turn it off, do the same in reverse: click On in the PROXY column on the portal's Domains page and remove the origin setting at the same time.

cPanel with Apache​

Apache 2.4.31 or later supports PROXY protocol through mod_remoteip, which cPanel installs with Apache.

  1. As root, create /etc/apache2/conf.d/userdata/ssl/2_4/stillorigin-proxy.conf (cPanel includes every .conf file in that folder in all HTTPS virtual hosts, and only HTTPS ones):

    <IfModule remoteip_module>
    RemoteIPProxyProtocol On
    RemoteIPProxyProtocolExceptions 127.0.0.1 ::1
    </IfModule>

    RemoteIPProxyProtocolExceptions lets connections from the server itself (cron jobs or scripts that load your own sites) work without the header. Add the server's own public IP if scripts call your sites through it.

  2. Rebuild the configuration and restart Apache, and turn PROXY protocol on in the portal (Domains page, PROXY column) at the same time:

    /usr/local/cpanel/scripts/rebuildhttpdconf
    /usr/local/cpanel/scripts/restartsrv_httpd
  3. For port 80, also set up X-Forwarded-For as in Trusting the sentry (in WHM: Apache Configuration › Include Editor › Pre VirtualHost Include, or the file /etc/apache2/conf.d/includes/pre_virtualhost_global.conf).

If an existing Cloudflare include on the server overrides your mod_remoteip settings, cPanel's own fix is touch /var/cpanel/no_apache_cloudflare, then rebuild and restart as above.

To undo, delete the file, rebuild and restart.

cPanel with LiteSpeed Enterprise​

LiteSpeed has PROXY protocol built in, and it falls back to a normal connection when the header isn't sent, so it is the safest option.

  1. In the LiteSpeed WebAdmin console, open Configuration › Server › Tuning.
  2. Under General, set PROXY protocol to your sentry addresses, comma-separated (for example 203.0.113.10, 203.0.113.11).
  3. Save and do a graceful restart.
  4. In the portal, open Domains and click Off in the PROXY column for each domain on that origin, then confirm.

Only the listed addresses may send the header. For port 80, also set Use Client IP in Header as in Trusting the sentry.

DirectAdmin with Apache​

This covers DirectAdmin servers where Apache answers HTTPS itself. If nginx is in front of Apache (nginx_apache), see Other setups.

  1. Check that mod_remoteip is loaded: httpd -M | grep remoteip.

  2. Create these two files with the same content, so the setting goes into every HTTPS virtual host (domains and subdomains):

    • /usr/local/directadmin/data/templates/custom/virtual_host2_secure.conf.CUSTOM.post
    • /usr/local/directadmin/data/templates/custom/virtual_host2_secure_sub.conf.CUSTOM.post
    <IfModule remoteip_module>
    RemoteIPProxyProtocol On
    RemoteIPProxyProtocolExceptions 127.0.0.1 ::1
    </IfModule>
  3. Rewrite the configuration (this restarts Apache), and turn PROXY protocol on in the portal (Domains page, PROXY column) at the same time:

    da build rewrite_confs
  4. For port 80, set up X-Forwarded-For as in Trusting the sentry, for example in /etc/httpd/conf/extra/httpd-includes.conf.

To undo, delete both files and run da build rewrite_confs again.

Plesk​

Plesk doesn't document PROXY protocol, and its nginx and Apache configuration is generated from templates, so we don't recommend it on Plesk. Use one of these instead:

  • turn on Website protection for the domain, so the visitor address is always sent in X-Forwarded-For; or
  • leave HTTPS showing the sentry address and rely on the sentry's logs and the portal for visitor addresses.

For port 80, follow Plesk's own guide for X-Forwarded-For (in Apache & nginx Settings › Additional nginx directives):

set_real_ip_from <sentry-ip-1>;
set_real_ip_from <sentry-ip-2>;
real_ip_header X-Forwarded-For;
real_ip_recursive on;

Enhance​

Enhance doesn't document PROXY protocol for its web servers, so leave it off for Enhance origins. Use Website protection for domains where you need the visitor address over HTTPS, and X-Forwarded-For for port 80. If Enhance support confirms PROXY protocol for your setup, follow their steps and then turn it on in the portal on the Domains page.

Other setups​

Plain nginx (or nginx in front of Apache) needs proxy_protocol on the HTTPS listen line, plus the trusted sentry addresses:

listen 443 ssl proxy_protocol;
set_real_ip_from <sentry-ip-1>;
set_real_ip_from <sentry-ip-2>;
real_ip_header proxy_protocol;

Set this on every server block that listens on that address and port. On a panel that generates the nginx configuration, ask the panel vendor how to do this in a way that survives updates. If you aren't sure, open a ticket before you turn PROXY protocol on.

If HTTPS stops working​

Turn PROXY protocol off for the origin's domains on the portal's Domains page, or remove the setting from the origin, whichever you changed last, so both sides match again.