Nginx将http子域重定向到https

时间:2015-06-10 18:36:57

标签: ubuntu redirect ssl nginx rewrite

我有一个包含3个子域的域名:

 - example.com (main domain)
 - api.example.com
 - blog.example.com
 - support.example.com (just a cname to point to zendesk)

我在 Nginx 上有这3个配置:

API

# HTTP server
server {
    listen       80;
    server_name  api.example.com;
    return 301 https://api.example.com$request_uri;
}


# HTTPS server
server {
    ssl          on;
    listen       443;
    server_name  api.example.com;

    ssl_certificate APIcert.crt;
    ssl_certificate_key APIcert.key;

    #root configuration.....
}

博客

server {
    listen 80;
    server_name blog.example.com;

    root /var/www/blog;
    index index.php index.html index.htm;

网站/主域

server {
    listen 80;
    listen 443 ssl;
    server_name www.example.com;
    return 301 https://example.com$request_uri;

    location ~ \.(php|html)$ {
        deny  all;
    }
}

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

    location ~ \.(php|html)$ {
        deny  all;
    }
}

server {
    ssl on;
    listen 443 ssl;
    ssl_certificate  mycert.crt;
    ssl_certificate_key  mycert.key;
    server_name example.com;

    root /var/www/frontend;
    .....
}

我的问题

2 个答案:

答案 0 :(得分:4)

您的网络服务器设置为Strict-Transport-Security max-age=16070400; includeSubdomains

这将告诉网络浏览器仅使用https请求您的域名。如果您希望通过不安全的http访问子域blog,则需要从HTTP严格传输安全性(HSTS)中删除includeSubdomains并使用其他浏览器(或清除Firefox)。

https://www.ssllabs.com/ssltest/analyze.html?d=alooga.com.br

答案 1 :(得分:-1)

您收到SSL错误消息,因为您没有blog.alooga.com.br域的SSL证书。

SSL错误消息供您参考: