0

我在使用 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;
    }

}
4

1 回答 1

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 的绝对 URL

于 2013-07-20T13:15:12.087 回答