我正在使用cloudfront设置cdn。我的云端分布的起源是我的aws负载平衡器(ELB)。当我向云端请求而不是获取云端地址(cdn.mysite.com/images/image.jpg)时,它将被重定向到https://www.alio.com/images/image.jpg。我想通过我的nginx.conf为什么会这样做:Cloudfront Nginx重写导致问题
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?常驻;更改网址(当我删除重写我得到的CDN网址)。我有这个重写,以确保对我的网站的所有请求都是https。如果有办法做,而不是重写301重定向,或者如果我检测到它是云前台拨打ELB的电话,那么不要重写?
感谢,这个工作 – gprime