Para uma configuração multi-ambiente, tenho o seguinte:
link = > CloudFront = > link = > WordPress FastCGI
Isso funciona bem. No entanto, eu gostaria de ser capaz de ignorar o CloudFront para fins de depuração (colocando um robots.txt para evitar problemas de SEO).
link = > WordPress FastCGI
Meu problema é que o WordPress armazena URLs absolutas, então ainda retorna links CDN para qualquer conteúdo. Eu gostaria que o nginx reescrevesse de forma transparente www-origin.example.com para www.example.com, incluindo os links nas respostas. Alguma ponteira? Eu tentei definir fastcgi_param HTTP_HOST sem sucesso.
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;
}
}
** Atualização 27-02
Por enquanto eu tenho o seguinte. Qualquer comentário seria apreciado:
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;
}