nginx转发www到https

时间:2017-03-12 15:18:59

标签: nginx https no-www

我正在使用nginx如果我打电话给www..com我的浏览器无法找到任何内容而且没有显示页面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;
    }
}

UPDATE-1

error.log中

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>/"

1 个答案:

答案 0 :(得分:0)

也许您忘了 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向你展示一切))