Nginx在https域上提供非安全资源

时间:2013-07-20 03:42:33

标签: magento ssl

我在使用SSL证书设置服务器时遇到了一些问题。我能够很好地安装证书并重新启动nginx服务。但是,当我尝试加载我的网站时,我看到所有的img,css和js文件都是用http而不是https检索的。这是一个Magento网站。我的conf文件有问题吗?

server {
    listen 80;
    server_name www.my-domain.com;
    return 301 $scheme://my-domain.com$request_uri;
}

server {
    listen 80;
    listen 443 ssl;

    ssl_certificate     /etc/ssl/my-domain/my-domain_com.pem;
    ssl_certificate_key /etc/ssl/my-domain/my-domain_com.key;

    access_log /var/log/nginx/magento.local-access.log;
    error_log  /var/log/nginx/magento.local-error.log;

    server_name my-domain.com;
    root /var/www/my-domain;

    include conf/magento_rewrites.conf;
    include conf/magento_security.conf;

    # PHP handler
    location ~ \.php {
      ## Catch 404s that try_files miss
      if (!-e $request_filename) { rewrite / /index.php last; }

      ## Store code is defined in administration > Configuration > Manage Stores
      fastcgi_param MAGE_RUN_CODE default;
      fastcgi_param MAGE_RUN_TYPE store;

      # By default, only handle fcgi without caching
      include conf/magento_fcgi.conf;
    }

    # 404s are handled by front controller
    location @magefc {
      rewrite / /index.php;
    }

    # Last path match hands to magento or sets global cache-control
    location / {
      ## Maintenance page overrides front controller
      index index.html index.php;
      try_files $uri $uri/ @magefc;
      expires 24h;
    }

    rewrite ^/minify/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last;
    rewrite ^/skin/m/([0-9]+)(/.*.(js|css))$ /lib/minify/m.php?f=$2&d=$1 last;

    location /lib/minify/ {
        allow all;
    }

}

1 个答案:

答案 0 :(得分:0)

可能因为这是他们的调用方式,如果你需要以https的方式提供服务,我会创建一个空的服务器来监听80并重定向到https

server {
    # listen 80; delete this part
    listen 443 ssl;
    # the rest of the config
}
# add this server
server {
    listen 80;
    server_name example.com;
    location / # or a more specific location '~ \.(jpg|css|js|jpeg|png|gif)' {
        return https://example.com$request_uri;
    }
}

或者只修复css位置,它可能是带有http

的绝对网址