![重定向 HTTPS+IP 地址到域名](https://linux22.com/image/757116/%E9%87%8D%E5%AE%9A%E5%90%91%20HTTPS%2BIP%20%E5%9C%B0%E5%9D%80%E5%88%B0%E5%9F%9F%E5%90%8D.png)
因此我的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.4
到https://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;
}
}
谢谢你,祝你有美好的一天。