重定向 HTTPS+IP 地址到域名

重定向 HTTPS+IP 地址到域名

因此我的example.com配置文件成功将以下 URL 重定向到https://example.com/...

  • http://1.2.3.4
  • http://example.com
  • http://www.example.com
  • https://example.com
  • https://www.example.com

... 但不是https://1.2.3.4。我的问题是,如何重定向https://1.2.3.4https://example.com

我没有对default配置文件做任何更改。这是我的example.com配置文件:

server {
  listen 80;
  listen [::]:80;
  server_name www.example.com example.com 1.2.3.4;
  return 301 https://example.com$request_uri;
}

server {
  listen 443 ssl;
  ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
  server_name www.example.com 1.2.3.4;
  return 301 https://example.com$request_uri;
}

server {
  listen [::]:443 ssl ipv6only=on;
  listen 443 ssl;
  ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
  ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
  server_name example.com;

  include /etc/letsencrypt/options-ssl-nginx.conf;
  ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

  root /var/www/example.com/html;
  index index.html index.htm index.nginx-debian.html;
  location / {
    try_files $uri $uri/ =404;
  }
}

谢谢你,祝你有美好的一天。

相关内容