Nginx会将图像域http重新映射为https,但我不希望静态服务器为https

时间:2017-11-06 03:57:45

标签: wordpress nginx

我有一个带有https协议的wordpress网站,通过配置nginx 301重定向:

server {
    listen       80;
    server_name  xxx.com;
    return       301 https://$server_name$request_uri;
}

server {
    listen       443 ssl;
    server_name  xxx.com;
    ssl_certificate     conf.d/xxx.crt;
    ssl_certificate_key conf.d/xxx.key;
}

我的文章与静态服务器有一些图像链接,如: http://yyy.com/1.png

但是当我访问这篇文章时:它将是https://yyy.com/1.png,如何配置仍然可以使用http作为图像静态服务器的nginx?

1 个答案:

答案 0 :(得分:0)

你可以使用下面的配置

来做到这一点
server {
    listen       80;
    server_name  xxx.com;
    location ~* \.(png|ico|jpeg)$ {
       root <your root folder>;
       try_files $uri =404;
    }

    location / {
       return       301 https://$server_name$request_uri;
    }
}

server {
    listen       443 ssl;
    server_name  xxx.com;
    ssl_certificate     conf.d/xxx.crt;
    ssl_certificate_key conf.d/xxx.key;
}