CDN 背後的 WordPress 網站;想要 -origin 繞過 CDN

CDN 背後的 WordPress 網站;想要 -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;
    }

相關內容