WordPress 网站采用 CDN 方式;希望 -origin 能够绕过 CDN

WordPress 网站采用 CDN 方式;希望 -origin 能够绕过 CDN

对于多环境设置我有以下内容:

https://www.example.com/=> 云端 =>https://www-origin.example.com/=> WordPress FastCGI

这很好用。不过,我希望能够绕过 CloudFront 进行调试(放置 robots.txt 以防止 SEO 问题)。

https://www-origin.example.com/=> WordPress FastCGI

我的问题是 WordPress 存储绝对 URL,因此仍然会返回任何内容的 CDN 链接。我希望 nginx 透明地将 www-origin.example.com 重写为 www.example.com,包括响应中的链接。有什么提示吗?我尝试设置 fastcgi_param HTTP_HOST,但没有用。

server {
    listen 80;
    listen [::]:80;
    root /data/html/wordpress;
    index  index.php index.html index.htm;
    server_name  _;
    client_max_body_size 100M;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

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

    location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
    }
}

server {
    listen 80;
    root /data/html/wordpress;
    index  index.php index.html index.htm;
    server_name www-origin.example.com;
    client_max_body_size 100M;

    access_log /var/log/nginx/origin-access.log;
    error_log /var/log/nginx/origin-error.log;

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

    location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         fastcgi_param HTTP_HOST www.example.com;
         include fastcgi_params;
    }
}

** 更新 27-02

目前我得到以下信息。任何评论都值得赞赏:

server {
    server_name ~^(?<subdomain>.+)-origin(?<domain>\..+\..+)$;

    listen 80;

    access_log /var/log/nginx/access-origin.log;
    error_log /var/log/nginx/error-origin.log;

    location /test
    {
        root   /sites/$subdomain$domain;
    }


    location / { 
      proxy_pass http://127.0.0.1:80;
      proxy_redirect "https://$subdomain$domain/" "https://subdomain-origin$domain/";
      sub_filter_once off;
      sub_filter "$subdomain$domain" "$subdomain-origin$domain";
      sub_filter_types *;
      proxy_http_version 1.1;
      proxy_set_header Accept-Encoding "";

      proxy_set_header Host $subdomain$domain;

      # include details about the original request
      proxy_set_header X-Original-Host $http_host;
      proxy_set_header X-Original-Scheme $scheme;
      proxy_set_header X-Forwarded-For $remote_addr;
    }
}

server {
    listen 80 default_server;
    listen [::]:80;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    root /data/html/wordpress;
    index  index.php index.html index.htm;
    server_name _;

    client_max_body_size 100M;

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

相关内容