Publishing an internal website through FRP is straightforward until HTTPS, SafeLine WAF, Nginx, and WordPress all become part of the same request path.

At that point, two problems commonly appear:

  • SafeLine or the origin server records the address of frpc or the reverse proxy instead of the visitor's public IP;
  • WordPress believes the original request used HTTP and generates insecure resource URLs, causing mixed-content errors.

Here's a complete deployment pattern that solves both problems without terminating TLS at FRP. FRP passes the original client address to SafeLine through Proxy Protocol v2. SafeLine restores that address and forwards it to the origin through X-Forwarded-For. WordPress then uses X-Forwarded-Proto to recognize the original HTTPS request.

Visitor
  ↓ HTTPS
Public frps
  ↓ FRP tunnel
Internal frpc
  ↓ HTTPS + Proxy Protocol v2
SafeLine WAF
  ↓ HTTP + X-Forwarded-For
Origin Nginx
  ↓
WordPress / PHP

All hostnames, IP addresses, paths, log names, and configuration filenames in this article are anonymized examples. Replace them with values from your own environment.

1. Example Deployment

ComponentAddress or portPurpose
Public frpsPublic FRP nodeReceives public HTTPS traffic
frpcRuns on the SafeLine hostForwards tunnel traffic to SafeLine
SafeLine WAF192.168.1.10WAF, TLS termination, and reverse proxy
Standard SafeLine HTTPS192.168.1.10:443Normal HTTPS listener
FRP-only SafeLine listener127.0.0.1:8443Accepts Proxy Protocol v2 from frpc
Origin Nginx192.168.1.20:80Hosts WordPress
Public hostnamewww.example.comCanonical public address
WordPress directory/var/www/example.comExample document root

The most important design rule: ordinary HTTPS clients and Proxy Protocol clients should not share the same listener. Keep port 443 as a normal HTTPS entry point and reserve port 8443 for frpc.

2. Why FRP Cannot Add X-Forwarded-For to an HTTPS Tunnel

With plain HTTP, a proxy can inspect the request and add a header such as:

X-Forwarded-For: 203.0.113.25

HTTPS is different. The HTTP headers are encrypted inside TLS, so FRP cannot read or modify them unless it terminates TLS.

Proxy Protocol solves this problem at the transport layer. Its header is sent before the TLS handshake:

Proxy Protocol v2 header
TLS ClientHello
Encrypted HTTPS request

This allows frpc to pass the original source address to SafeLine without decrypting the HTTPS request.

3. Why Proxy Protocol Requires a Dedicated Listener

Proxy Protocol is not an HTTP header. It appears at the beginning of the TCP stream, before TLS or HTTP data.

Once a listener is configured as follows:

listen 8443 ssl proxy_protocol;

every connection to that listener must begin with a valid Proxy Protocol header. A normal browser does not send one and therefore cannot connect directly to that port.

The reverse is also true. If frpc sends Proxy Protocol to a listener that does not expect it, SafeLine interprets the protocol header as TLS data and rejects the connection.

PortPurposeProxy Protocol
443Normal HTTPS accessDisabled
8443Dedicated frpc entry pointEnabled, version 2

Visitors continue to use the standard public URL:

https://www.example.com/

The public frps node receives the external connection and delivers it through the tunnel. The internal frpc process then connects to SafeLine on 127.0.0.1:8443.

4. Create a Dedicated SafeLine HTTPS Listener

Add a second HTTPS listener to the existing SafeLine site.

Hostname: www.example.com
HTTPS: enabled
Listener port: 8443
Upstream: http://192.168.1.20:80
Certificate: certificate for www.example.com

Keep the existing port 443 listener. Before Proxy Protocol is enabled manually, the generated configuration will usually contain:

listen 0.0.0.0:443 ssl http2;
listen 0.0.0.0:8443 ssl http2;

Only the FRP-specific 8443 listener should be changed. Do not enable Proxy Protocol on the standard 443 listener.

5. Enable Proxy Protocol in SafeLine Tengine

SafeLine site configurations are commonly stored under:

/data/safeline/resources/nginx/sites-enabled/

The generated filename varies between installations. Find the file containing the 8443 listener instead of assuming a fixed name:

grep -RnsE 'listen .*8443' \
  /data/safeline/resources/nginx/sites-enabled/

5.1 Store Backups Outside sites-enabled

Do not leave backup copies in sites-enabled. Nginx or Tengine may load every file in that directory, including files ending in .bak.

This can produce duplicate log_format, upstream, or server definitions, resulting in errors such as:

duplicate "log_format" name

Create a separate backup directory:

mkdir -p /data/safeline/config-backups

After locating the active configuration file, back it up there:

SITE_CONF="/data/safeline/resources/nginx/sites-enabled/REPLACE_WITH_ACTUAL_FILE"

cp -- "$SITE_CONF" \
  "/data/safeline/config-backups/$(basename "$SITE_CONF").$(date +%F-%H%M%S).bak"

5.2 Enable Proxy Protocol on Port 8443

Change:

listen 0.0.0.0:8443 ssl http2;

to:

listen 0.0.0.0:8443 ssl http2 proxy_protocol;

Because frpc and SafeLine run on the same host, and frpc connects through 127.0.0.1, trust only the loopback address:

set_real_ip_from 127.0.0.1;
real_ip_header proxy_protocol;
real_ip_recursive on;

The relevant part of the server configuration should resemble:

server {
    listen 0.0.0.0:443 ssl http2;
    listen 0.0.0.0:8443 ssl http2 proxy_protocol;

    server_name www.example.com;

    # Trust Proxy Protocol only from the local frpc process.
    set_real_ip_from 127.0.0.1;
    real_ip_header proxy_protocol;
    real_ip_recursive on;

    # Keep the SafeLine-managed certificate and proxy settings.
}

Never use set_real_ip_from 0.0.0.0/0; for convenience. The source address inside Proxy Protocol is asserted by the sender. Trusting every sender would allow another host to forge client addresses.

5.3 Optional Hardening: Bind Port 8443 to Loopback

If frpc and SafeLine will always run on the same host, restrict the listener further:

listen 127.0.0.1:8443 ssl http2 proxy_protocol;

This prevents other devices on the LAN from reaching the Proxy Protocol listener.

SafeLine may regenerate the file after a site edit or upgrade. If the loopback binding cannot be preserved, retain the generated 0.0.0.0:8443 listener and restrict access with host firewall rules.

5.4 Test and Reload Tengine

Test the configuration first:

docker exec safeline-tengine nginx -t

Reload only after the test succeeds:

docker exec safeline-tengine nginx -s reload

Verify the active configuration rather than relying only on the file that was edited:

docker exec safeline-tengine nginx -T 2>&1 \
  | grep -E 'listen .*8443|set_real_ip_from|real_ip_header|real_ip_recursive'

The output should include:

listen 0.0.0.0:8443 ssl http2 proxy_protocol;
set_real_ip_from 127.0.0.1;
real_ip_header proxy_protocol;
real_ip_recursive on;

If the listener is bound to loopback, the first line will contain 127.0.0.1:8443.

6. Configure the FRP Tunnel

When frpc and SafeLine run on the same host, configure the tunnel as follows:

Tunnel type: HTTPS
Hostname: www.example.com
Local IP: 127.0.0.1
Local port: 8443
Proxy Protocol: v2

Some managed FRP providers use a custom option such as:

proxy_protocol_version = v2

A modern upstream FRP TOML configuration may look like this:

[[proxies]]
name = "example-https"
type = "https"
localIP = "127.0.0.1"
localPort = 8443
customDomains = ["www.example.com"]

transport.proxyProtocolVersion = "v2"

Configuration syntax varies between FRP versions and hosting providers. When using a managed control panel, follow the provider's documentation instead of combining examples from different formats.

Restart or reconnect the tunnel after saving the change. Saving a control-panel setting may not update an frpc process that is already running.

Both sides must agree: frpc must send Proxy Protocol v2, and SafeLine port 8443 must expect it. Enabling the feature on only one side will break the TLS connection.

7. Configure SafeLine's Upstream Headers

SafeLine may continue using plain HTTP to reach the internal origin:

http://192.168.1.20:80

Internal HTTP does not itself cause mixed content. Mixed content occurs when a browser loads a page over HTTPS but receives resource URLs beginning with http://.

SafeLine should preserve the public hostname and pass headers equivalent to:

Host: www.example.com
X-Forwarded-For: 203.0.113.25
X-Real-IP: 203.0.113.25
X-Forwarded-Proto: https
X-Forwarded-Host: www.example.com
X-Forwarded-Port: 443

A typical reverse-proxy configuration contains directives similar to:

proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port 443;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;

Because the FRP-specific 8443 listener uses TLS, $scheme is https for requests arriving through that path.

The physical SafeLine listener uses port 8443, while the public URL uses port 443. Explicitly sending X-Forwarded-Port: 443 prevents the internal listener port from leaking into application-generated URLs.

8. Configure Real IP Handling on the Origin Nginx Server

The origin at 192.168.1.20 receives an ordinary HTTP connection from SafeLine at 192.168.1.10. At this stage, the origin should trust X-Forwarded-For only when the immediate connection comes from SafeLine.

server {
    listen 80;

    server_name www.example.com;

    # Trust only the SafeLine server.
    set_real_ip_from 192.168.1.10;
    real_ip_header X-Forwarded-For;
    real_ip_recursive on;

    root /var/www/example.com;
    index index.php index.html;

    # Keep the existing WordPress, PHP, cache, and rewrite rules.
}

Do not enable Proxy Protocol on the origin listener:

listen 80 proxy_protocol;

SafeLine sends normal HTTP to the origin. If the origin requires Proxy Protocol, health checks and upstream requests will fail, often with an error such as:

broken header while reading PROXY protocol

Test and reload the origin configuration:

nginx -t
systemctl reload nginx

Where possible, use firewall rules to allow access to origin port 80 only from 192.168.1.10. This prevents clients from bypassing SafeLine and makes forwarded-header trust safer.

9. Make WordPress Recognize the Original HTTPS Request

The external connection uses HTTPS, while SafeLine connects to WordPress over internal HTTP:

Browser ── HTTPS ──> SafeLine
SafeLine ── HTTP  ──> Nginx / WordPress

If WordPress examines only the internal connection, it may believe that the request used HTTP and generate URLs such as:

http://www.example.com/wp-content/themes/example/style.css

The browser then blocks the CSS, JavaScript, fonts, images, or API requests because the page itself was loaded over HTTPS.

9.1 Process X-Forwarded-Proto in wp-config.php

Edit:

/var/www/example.com/wp-config.php

Add the following before:

/* That's all, stop editing! Happy publishing. */
/**
 * TLS is terminated by the trusted SafeLine reverse proxy.
 * SafeLine connects to the origin over HTTP and reports the
 * original public protocol through X-Forwarded-Proto.
 *
 * The origin must not be directly reachable by untrusted clients.
 */
if (
    isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
    in_array(
        'https',
        array_map(
            'trim',
            explode(',', strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']))
        ),
        true
    )
) {
    $_SERVER['HTTPS'] = 'on';
    $_SERVER['SERVER_PORT'] = 443;
}

/**
 * Canonical public site address.
 */
define('WP_HOME', 'https://www.example.com');
define('WP_SITEURL', 'https://www.example.com');

/**
 * Require HTTPS for WordPress login and administration.
 */
define('FORCE_SSL_ADMIN', true);

This code must run before:

require_once ABSPATH . 'wp-settings.php';

Otherwise, WordPress may already have completed protocol detection.

The origin must also be protected from direct access. If arbitrary clients can reach it, they may supply their own X-Forwarded-Proto header.

9.2 Correct the WordPress URL Options

cd /var/www/example.com

wp option update home 'https://www.example.com' --allow-root
wp option update siteurl 'https://www.example.com' --allow-root

If WP-CLI runs as the web-server user instead of root, omit --allow-root.

9.3 Replace Historical HTTP URLs Safely

Back up the database first:

cd /var/www/example.com

wp db export \
  "/root/example-before-https-$(date +%F-%H%M%S).sql" \
  --allow-root

Run a dry run:

wp search-replace \
  'http://www.example.com' \
  'https://www.example.com' \
  --all-tables-with-prefix \
  --precise \
  --skip-columns=guid \
  --dry-run \
  --allow-root

If the results are correct, perform the replacement:

wp search-replace \
  'http://www.example.com' \
  'https://www.example.com' \
  --all-tables-with-prefix \
  --precise \
  --skip-columns=guid \
  --allow-root

Also check any old non-www hostname or internal address previously used by the site:

wp search-replace \
  'http://example.com' \
  'https://www.example.com' \
  --all-tables-with-prefix \
  --precise \
  --skip-columns=guid \
  --dry-run \
  --allow-root

wp search-replace \
  'http://192.168.1.20' \
  'https://www.example.com' \
  --all-tables-with-prefix \
  --precise \
  --skip-columns=guid \
  --dry-run \
  --allow-root

Review the dry-run output before removing --dry-run.

Avoid a database-wide SQL string replacement. WordPress themes and plugins often store PHP-serialized data, and a basic SQL replacement can corrupt serialized string lengths. WP-CLI safely handles those structures.

9.4 Clear Caches and Regenerate Assets

cd /var/www/example.com
wp cache flush --allow-root

Also clear or rebuild:

  • WordPress page caches;
  • Redis or other object caches;
  • CSS and JavaScript optimization caches;
  • Elementor or other page-builder CSS;
  • theme-generated assets;
  • SafeLine and CDN caches;
  • browser caches.

Use a forced refresh or a private browsing window when testing.

9.5 Do Not Redirect Based Only on the Origin $scheme

Do not add this rule to the origin:

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

SafeLine always reaches the origin over HTTP, so the origin's $scheme remains http. A redirect based only on that value can create an infinite redirect loop.

Perform public HTTP-to-HTTPS redirection at SafeLine or another trusted edge layer.

10. Verify the Real Client IP End to End

10.1 Verify the Address in SafeLine

Use a phone on a mobile network and open:

https://api.ipify.org/

Record the public address, visit the website, and inspect the request in SafeLine. The client address shown by SafeLine should match the address reported by the IP-checking service.

10.2 Verify the Address at the Origin

Visit a unique test URL:

https://www.example.com/?iptest=1

Then inspect the origin access log:

tail -n 30 /var/log/nginx/example.com.access.log

A successful entry should begin with the visitor's public address:

203.0.113.25 - - [...] "GET /?iptest=1 HTTP/1.1" 200 ...

Periodic requests from 192.168.1.10 with a SafeLine-related user agent are usually health checks and do not indicate a failure.

10.3 Add a Temporary Diagnostic Log

Inside the origin Nginx http {} block, add:

log_format realip_check
    'client=$remote_addr '
    'peer=$realip_remote_addr '
    'xff="$http_x_forwarded_for" '
    'xreal="$http_x_real_ip" '
    'proto="$http_x_forwarded_proto" '
    '"$request" $status';

Inside the site's server {} block, add:

access_log /var/log/nginx/realip-check.log realip_check;

An ideal entry resembles:

client=203.0.113.25
peer=192.168.1.10
xff="203.0.113.25"
xreal="203.0.113.25"
proto="https"

Remove the temporary log after troubleshooting if it is no longer needed.

11. Verify That Mixed Content Is Gone

Search the rendered home page for insecure URLs:

curl -ks https://www.example.com/ \
  | grep -Eo "http://[^\"' <>]+" \
  | sort -u

Check the site hostname specifically:

curl -ks https://www.example.com/ \
  | grep -Eo "http://(www\.)?example\.com[^\"' <>]*" \
  | sort -u

Ideally, both commands return no output.

In the browser developer tools:

  • confirm that the Console contains no mixed-content warnings;
  • inspect CSS, JavaScript, fonts, images, and API requests in the Network panel;
  • verify that internal resources use HTTPS;
  • verify that resources return HTTP 200 or 304;
  • verify that stylesheets return the correct text/css content type;
  • make sure SafeLine is not replacing a resource with a challenge or error page.

12. Troubleshooting

Problem 1: The Website Stops Working After Proxy Protocol Is Enabled

The most likely cause is a mismatch between frpc and SafeLine.

frpcSafeLine 8443Result
Proxy Protocol v2 enabledproxy_protocol enabledCorrect
DisabledEnabledSafeLine attempts to parse TLS as Proxy Protocol
EnabledDisabledSafeLine attempts to parse Proxy Protocol as TLS
DisabledDisabledThe site works, but the real IP is lost

Problem 2: SafeLine Shows 127.0.0.1 as the Client

This usually means that frpc reached SafeLine, but SafeLine did not process the Proxy Protocol header.

docker exec safeline-tengine nginx -T 2>&1 \
  | grep -E 'listen .*8443|set_real_ip_from|real_ip_header'

Confirm that:

  • the 8443 listener contains proxy_protocol;
  • real_ip_header proxy_protocol; is active;
  • 127.0.0.1 is trusted;
  • the FRP tunnel is sending version 2;
  • the tunnel was restarted after the change.

Problem 3: SafeLine Has the Real IP, but the Origin Shows 192.168.1.10

Verify that the active origin virtual host contains:

set_real_ip_from 192.168.1.10;
real_ip_header X-Forwarded-For;
real_ip_recursive on;

Also confirm that SafeLine forwards X-Forwarded-For.

Problem 4: SafeLine Cannot Reach the Origin

Check whether the origin was incorrectly configured with:

listen 80 proxy_protocol;

The origin must use a normal HTTP listener:

listen 80;

Also check the origin firewall and the SafeLine upstream address.

Problem 5: Nginx Reports a Duplicate Configuration Definition

A backup file may have been left inside sites-enabled. List matching files before moving anything:

find /data/safeline/resources/nginx/sites-enabled/ \
  -maxdepth 1 -type f -name '*.bak*' -print

If the output contains only backup files, move them:

mkdir -p /data/safeline/config-backups

find /data/safeline/resources/nginx/sites-enabled/ \
  -maxdepth 1 -type f -name '*.bak*' \
  -exec mv -t /data/safeline/config-backups/ -- {} +

Problem 6: HTML Loads, but CSS and JavaScript Do Not

  • Confirm that SafeLine sends X-Forwarded-Proto: https;
  • confirm that wp-config.php processes the header before WordPress loads;
  • confirm that WP_HOME and WP_SITEURL use HTTPS;
  • check whether the database still contains old HTTP URLs;
  • regenerate page-builder and theme assets;
  • clear WordPress, SafeLine, CDN, and browser caches;
  • make sure SafeLine is not returning a challenge page for static assets.

13. Security Notes

  1. Trust only the actual frpc source. In this example, frpc is local, so SafeLine trusts only 127.0.0.1.
  2. Never trust 0.0.0.0/0 for Proxy Protocol. An untrusted sender could forge client addresses.
  3. Do not expose port 8443 publicly. Bind it to loopback or restrict it with firewall rules.
  4. The origin should trust only SafeLine. Here, the trusted proxy is 192.168.1.10.
  5. Restrict direct access to the origin. Ideally, only SafeLine should be able to reach origin port 80.
  6. Do not blindly trust client-supplied forwarding headers. A trusted edge proxy should normalize or overwrite them.
  7. Protect TLS private keys. Never upload private keys to chat services, public repositories, or unsecured storage.
  8. Enable HSTS only after HTTPS is stable. Avoid enabling preload during initial testing.
  9. Use reserved example values in public documentation. example.com and 203.0.113.0/24 are intended for documentation.

14. SafeLine May Overwrite Manual Changes

SafeLine may regenerate the site configuration after:

  • editing the site in the dashboard;
  • changing listener ports;
  • replacing or renewing the certificate;
  • upgrading SafeLine;
  • recreating the safeline-tengine container;
  • deleting and recreating the site.

After any of these operations, verify the active configuration:

docker exec safeline-tengine nginx -T 2>&1 \
  | grep -E 'listen .*8443|set_real_ip_from|real_ip_header|real_ip_recursive'

Confirm that the following settings still exist:

listen 0.0.0.0:8443 ssl http2 proxy_protocol;

set_real_ip_from 127.0.0.1;
real_ip_header proxy_protocol;
real_ip_recursive on;

For a long-running deployment, consider automating this check instead of waiting for the site to fail.

15. Final Configuration Summary

FRP

Type: HTTPS
Hostname: www.example.com
Local IP: 127.0.0.1
Local port: 8443
Proxy Protocol: v2

SafeLine Tengine

listen 0.0.0.0:443 ssl http2;
listen 127.0.0.1:8443 ssl http2 proxy_protocol;

set_real_ip_from 127.0.0.1;
real_ip_header proxy_protocol;
real_ip_recursive on;

SafeLine Upstream

http://192.168.1.20:80

Origin Nginx

listen 80;

set_real_ip_from 192.168.1.10;
real_ip_header X-Forwarded-For;
real_ip_recursive on;

WordPress

if (
    isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
    in_array(
        'https',
        array_map(
            'trim',
            explode(',', strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']))
        ),
        true
    )
) {
    $_SERVER['HTTPS'] = 'on';
    $_SERVER['SERVER_PORT'] = 443;
}

define('WP_HOME', 'https://www.example.com');
define('WP_SITEURL', 'https://www.example.com');
define('FORCE_SSL_ADMIN', true);

Conclusion

The correct solution is not to make WordPress guess the visitor's address. The real client IP must pass through every layer using an explicit and trusted mechanism:

FRP sends Proxy Protocol v2
          ↓
SafeLine trusts the local frpc process and restores the client IP
          ↓
SafeLine forwards the address through X-Forwarded-For
          ↓
The origin trusts only SafeLine
          ↓
WordPress receives the correct REMOTE_ADDR

The original HTTPS protocol must travel through the stack as well:

Public HTTPS request
          ↓
SafeLine sends X-Forwarded-Proto: https
          ↓
WordPress restores HTTPS awareness
          ↓
WordPress generates HTTPS resource URLs

Once both chains remain intact, SafeLine logs, origin logs, WordPress access control, secure administration, and front-end resources can all work as expected.


There are phalanges that can truly revere and believe.