首页 > 解决方案 > NGINX 重定向到 www 域不起作用

问题描述

我有一个包含在 nginx.conf 中的 mywebsite.conf。文件是这样的:

server {
    listen 80;
    server_name www.mywebsite.nl;
    return 301 https://www.mywebsite.nl$request_uri;
}

server {
    listen 80;
    server_name mywebsite.nl;
    return 301 https://www.mywebsite.nl$request_uri;
}

server {
    listen 443 ssl;
    server_name mywebsite.nl;
    ...
    return 301 https://www.mywebsite.nl$request_uri;
}

server {
    listen 443 ssl http2;
    server_name www.mywebsite.nl;
    ...
}

此配置适用于我所有的网站。但不知何故,这次http://mywebsite.nl没有重定向到https://www.mywebsite.nl

我不知道为什么。DNS 指向服务器。缓存是隐身的。

我重新加载并重新启动了nginx。尝试了新的浏览器。使用https://wheregoes.com对其进行测试。

有任何想法吗?

curl的输出是:

* Trying 37.97.xxx.xx...
* TCP_NODELAY set
* Connected to mywebsite.nl (37.97.xxx.xx) port 80 (#0)
> HEAD / HTTP/1.1
> Host: mywebsite.nl
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Server: nginx/1.14.0 (Ubuntu)
Server: nginx/1.14.0 (Ubuntu)
< Date: Wed, 14 Jul 2021 05:55:03 GMT
Date: Wed, 14 Jul 2021 05:55:03 GMT
< Content-Type: text/html
Content-Type: text/html
< Content-Length: 612
Content-Length: 612
< Last-Modified: Wed, 17 Apr 2019 18:42:45 GMT
Last-Modified: Wed, 17 Apr 2019 18:42:45 GMT
< Connection: keep-alive
Connection: keep-alive
< ETag: "5cb773a5-264"
ETag: "5cb773a5-264"
< Accept-Ranges: bytes
Accept-Ranges: bytes

标签: nginx

解决方案


推荐阅读