【问题标题】:nginx, Magento & Cloudfrontnginx、Magento 和 Cloudfront
【发布时间】:2014-03-07 03:19:45
【问题描述】:

我继承了一个运行 Magento 和 nginx 的网站。我对 nginx 几乎一无所知,但对 Magento 也有相当多的了解。该站点配置为使用 Amazon Cloudfront CDN,但是所有图像、js 和 css 都将 301 重定向返回到源站点。我有一个运行 Apache 的开发站点,它具有相同的 Magento、MySQL 和 Cloudfront 设置,该设置可以正常运行,所以我很确定这是 nginx 的配置文件的问题。文件中写入了一些重写,我的假设是,当在 skin.mydomain.com 上请求资产时,它会重定向到 www.mydomain.com,而不是从 CDN 提供文件。我为 js.mydomain.com、skin.mydomain.com 和 cloud.mydomain.com 设置了 CNAME 记录,它们都指向同一个 Cloudfront CDN。以下是似乎适用的 nginx 配置文件部分:

server {
   listen 80;
   ##127.0.0.1:8080
   server_name mydomain.com;
   rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
}

server {
    listen 80;
    ##127.0.0.1:8080 default
        ## SSL directives might go here
        listen 443 default ssl;
        ssl_certificate     /etc/nginx/
        ssl_certificate_key /etc/nginx/

    server_name www.mydomain.com;
    ## *.mydomain.com; Domain is here twice so server_name_in_redirect will favour the www
    root /var/www/magento;

    location / {
        index index.html index.php; ## Allow a static html file to be shown first
        try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler
        expires 30d;
        if ($request_uri ~* "\.(ico|css|js|gif|jpe?g|png)$") {
            access_log off;
            expires max;
        }
        port_in_redirect off;
    }

任何帮助都将不胜感激,因为我几乎整天都在处理这个问题,并且想在某个时候停止处理它。

谢谢!

【问题讨论】:

    标签: magento nginx amazon-cloudfront


    【解决方案1】:

    似乎第一个 server 指令正在强制重写 www。

    server {
     . . .
        rewrite / $scheme://www.$host$request_uri permanent; ## Forcibly prepend a www
     . . . 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-09
      • 2021-03-19
      • 1970-01-01
      • 2021-12-26
      • 2016-02-05
      • 2015-01-03
      • 1970-01-01
      • 2021-08-19
      相关资源
      最近更新 更多