0

I have two VPS running. One is running HAProxy and another one is running WordPress. Both VPS has private networking enabled and I can curl the WordPress site fine from HAProxy server using its private IP address.

Here is URL settings for my WordPress site:

The HAProxy is doing SSL termination in this case because I'm planning to install more WordPress sites later with the following URLs:

  • my-website.com/blog (WordPress #1)
  • my-website.com/foo (WordPress #2)
  • my-website.com/bar (WordPress #3)

Here is my config for HAProxy.

global
  # default global config goes here
  maxconn 2048
  tune.ssl.default-dh-param 2048

defaults
    log global
    mode    http
  option forwardfor
  option http-server-close
    option  httplog
    option  dontlognull
  timeout connect 5000
  timeout client  50000
  timeout server  50000
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http
  stats enable
  stats uri /stats
  stats realm Haproxy\ Statistics
  stats auth xxx:xxx

frontend my-wordpress-frontend
  bind *:443 ssl crt /etc/ssl/private/my-website.com.pem
  option http-server-close
  http-request set-header X-Forwarded-Proto https if { ssl_fc }
  acl blog path_beg /blog
  acl wpadmin path_beg /wp-
  acl blog_search query -m reg ^s=.*$
  acl blog_preview query -m reg ^p=.*$
  acl root path /
  redirect location https://my-website.com/blog/ if root
  use_backend my-wordpress-backend if blog OR blog wpadmin OR blog blog_search OR blog blog_preview
  default_backend my-wordpress-backend

backend my-wordpress-backend
   redirect scheme https if !{ ssl_fc }
   reqrep ^([^\ :]*)\ /blog/(.*) \1\ /\2
   reqrep ^([^\ :]*)\ /blog/wp-admin/(.*) \1\ /\2
   cookie SERVERID insert indirect nocache
   server www-1 private_ip_address:80 check cookie

Everything looks fine except one thing. I'm able to see the login page at https://my-website.com/blog/wp-login.php. But, after I login, it redirects me to https://my-website.com/wp-admin.

This is not what I want. I was expecting to get https://my-website.com/blog/wp-admin.

I added this to my wp-config.php but it didn't work:

// Start custom config ---
define( 'FORCE_SSL_ADMIN', true );
define('FORCE_SSL_LOGIN', true);
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS']='on';
// End custom config ---

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

Did I miss something here? What is wrong here?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.