【问题标题】:nginx forward www to httpsnginx 转发 www 到 https
【发布时间】:2017-03-12 15:18:58
【问题描述】:

如果我调用 www..com,我正在使用 nginx,我的浏览器找不到任何内容,并且没有显示页面 https://.com 和 .com 工作正常。

这是我的 conf 文件,尝试了一些不同的配置,但它们无助于解决我的问题

# HTTP — redirect all traffic to HTTPS
server {
    listen 80;
    listen [::]:80 default_server ipv6only=on;
    return 301 https://$host$request_uri;
}


# HTTPS — proxy all requests to the Node app
server {
    # Enable HTTP/2
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name <MY-DOMAIN>;

    # Use the Let’s Encrypt certificates
    ssl                 on;
    ssl_certificate     /etc/letsencrypt/live/<MY-DOMAIN>/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/<MY-DOMAIN>/privkey.pem;

    # Include the SSL configuration from cipherli.st
    include /etc/nginx/conf.d/ssl-params.conf;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://localhost:8080;
        proxy_ssl_session_reuse off;
        proxy_set_header Host $http_host;
        proxy_cache_bypass $http_upgrade;
        proxy_redirect off;
    }

    location /api {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://localhost:3000;
        proxy_ssl_session_reuse off;
        proxy_set_header Host $http_host;
        proxy_cache_bypass $http_upgrade;
        proxy_redirect off;
    }
}

更新-1

错误日志

2017/03/12 16:40:17 [warn] 23185#23185: *59 an upstream response is buffered to a temporary file /var/cache/nginx/proxy_temp/1/00/0000000001 while reading upstream, client: 91.22.34.177, server: <MY-DOMAIN>, request: "GET /bundle.js HTTP/1.1", upstream: "http://127.0.0.1:8080/bundle.js", host: "<MY-DOMAIN>", referrer: "https://<MY-DOMAIN>/"

【问题讨论】:

    标签: nginx https no-www


    【解决方案1】:

    也许你忘记了 server_name 指令:

    server {
        listen 80;
        listen [::]:80 default_server;
    
        server_name <MY-DOMAIN>;
    
        return 301 https://$server_name$request_uri;
    }
    

    无论如何/var/log/nginx/error.log 向你展示一切))

    【讨论】:

    • 重读你的问题——对我来说还不够清楚——如果你想让读者从 www.blabla.com 到https://blabla.com,你需要server { listen 80; server_name www.blabla.com; return 301 http://blabla.com$request_uri; } server { listen 80; server_name blabla.com; ... }stackoverflow.com/questions/7947030/…
    • 奇怪,即使是两个服务器块声明也没有帮助,error.log 也不是很有帮助... -.-
    猜你喜欢
    • 2021-05-04
    • 2015-02-13
    • 2018-04-22
    • 1970-01-01
    • 1970-01-01
    • 2020-03-21
    • 2016-03-10
    • 2019-06-04
    • 2018-06-23
    相关资源
    最近更新 更多