banner
LAPLACE

王友元's blog

停下来前一定要想好下次开始时需要做的事情
telegram
x
email

WordPress - Reverse Proxy and Analogous Examples

The backend machine is configured with high specifications, and the frontend machine (line) has a fast speed; at this point, we should naturally think of using reverse proxy to accelerate user access speed.

This article takes WordPress as an example and records some precautions during the setup: if you encounter stylesheet failure, backend inaccessible, or too many redirects, you can refer to the content below!

Preparation#

  • Fast server A
  • Backend source server B

First, an effective nginx reverse proxy requires that the source site can be accessed normally by domain name, for example, the www.laplace.cc we are preparing to set up.

If www.laplace.cc is accessible, it means it is resolved on Machine B. What we need to do is to resolve www.laplace.cc on Machine A, which is contradictory and needs to be done as follows:

Bind another domain name on Machine B#

For example, mirror.laplace.cc

Bind the target domain name on Machine A#

For example, www.laplace.cc, then edit the nginx reverse proxy file to point to mirror.laplace.cc

Summary#

  • The backend website cannot be IP:port;
  • The backend needs to enable SSL;
  • The fixed link in the WordPress backend needs to be set to the target domain name (for example, www.laplace.cc);
  • Bind another domain name on the backend for the frontend to reverse proxy it;
  • The frontend and backend can use the same SSL certificate!
  • In the reverse proxy rules, the source site should have https (for example, https://mirror.laplace.cc)
  • Below is an example of the setup

Detailed Configuration:#

Backend B Machine Setup#

  1. Bind and resolve the target domain name and any arbitrary domain name
    Example:
www.laplace.cc
laplace.cc

mirror.laplace.cc
  1. Configure SSL (either www.laplace.cc or wildcard)

  2. Configure WordPress link rewrite rules (rewrite)
    WordPress example:

location /
{
	 try_files $uri $uri/ /index.php?$args;
}

rewrite /wp-admin$ $scheme://$host$uri/ permanent;

Frontend A Machine Setup#

  1. Bind and resolve the target domain name
www.laplace.cc
laplace.cc
  1. Enable reverse proxy, pointing to https://mirror.laplace.cc
    An example:
#PROXY-START/

location ^~ /
{
    proxy_pass https://de-mirror.laplace.cc;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_http_version 1.1;
    # proxy_hide_header Upgrade;
    #Persistent connection related configuration

    add_header X-Cache $upstream_cache_status;
    #Set Nginx Cache

    set $static_filepC4FuOQB 0;
    if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
    {
        set $static_filepC4FuOQB 1;
        expires 1m;
    }
    if ( $static_filepC4FuOQB = 0 )
    {
        add_header Cache-Control no-cache;
    }
}
#PROXY-END/
  1. Configure SSL (either www.laplace.cc or wildcard)
Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.