[英]How to redirect HTTP URL with IP address to HTTPS URL with domain name?
如何在 Nginx 中将诸如http://192.0.2.4
的 URL 重定向到https://example.com
而不是https://192.0.2.4
?
就像 Google 通过将https://172.217.7.206
重定向到https://google.com
所做的那样
我的nginx配置:
#Redirect all traffic to HTTPS
server {
listen 80 default_server;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name www.example.com;
我不想要任何重写,因为它需要更多的资源。
如果您在服务器中收到的唯一域是 www.example.com,则此解决方案应该适合您。 这会侦听“ip”并将其重定向到 www.example.com。
server {
server_name 192.0.2.4;
return 301 https://www.example.com$request_uri;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.