【发布时间】:2016-02-05 04:46:24
【问题描述】:
我正在使用 cloudfront 设置一个 cdn。我的云端分发的来源是我的 aws 负载均衡器 (ELB)。当我向 cloudfront 发出请求而不是获取 cloudfront url (cdn.mysite.com/images/image.jpg) 时,它被重定向到https://www.alio.com/images/image.jpg。由于我的 nginx.conf,我弄清楚了为什么它会这样做:
server {
root /var/www/html/alio/public;
index index.php;
server_tokens off;
server_name www.alio.com;
location / {
if ($http_x_forwarded_proto != 'https') {
rewrite ^ https://$host$request_uri? permanent;
}
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
重写 ^ https://$host$request_uri?永恒的;更改 url(当我删除重写时,我得到 cdn url)。我进行了重写以确保对我网站的所有请求都是 https。如果我检测到它是云端调用 ELB,是否有办法代替重写 301 重定向或不进行重写?
【问题讨论】:
标签: amazon-web-services nginx url-rewriting amazon-cloudfront