简体   繁体   English

如何将带有 IP 地址的 HTTP URL 重定向到带有域名的 HTTPS URL?

[英]How to redirect HTTP URL with IP address to HTTPS URL with domain name?

How to redirect an URL such as http://192.0.2.4 to https://example.com and not https://192.0.2.4 in Nginx?如何在 Nginx 中将诸如http://192.0.2.4的 URL 重定向到https://example.com而不是https://192.0.2.4

Like Google is doing by redirecting https://172.217.7.206 to https://google.com就像 Google 通过将https://172.217.7.206重定向到https://google.com所做的那样

My nginx configuration:我的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;

I don't want any rewrite because it cost more resources.我不想要任何重写,因为它需要更多的资源。

Redirect all traffic to HTTPS将所有流量重定向到 HTTPS

If the only domain you recive in your server is www.example.com, this solution should work for you.如果您在服务器中收到的唯一域是 www.example.com,则此解决方案应该适合您。 This listens to the "ip" and redirects it to 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM