【问题标题】:IP address to domain redirection in NGINXNGINX 中的 IP 地址到域重定向
【发布时间】:2014-05-20 10:07:09
【问题描述】:

我的服务器正在运行 NGINX。我的问题是我的网站可以通过 IP 地址和域访问。但我希望当有人浏览 IP 地址时,用户应该被重定向到我的域。 示例 :: 当任何人浏览http://107.170.126.xxx 时,他应该被重定向到http://mydomain.com

请问有人可以帮助我吗?在此先感谢

【问题讨论】:

    标签: redirect nginx ip url-redirection http-redirect


    【解决方案1】:

    因此您可以在站点可用的配置文件中添加服务器块,如下所示

    server {
    listen 80;
    server_name 111.11.111.111;
    
    return 301 $scheme://yourname.com$request_uri;
    

    }

    所以上面的代码将确保如果你输入 111.11.111.111 它会重定向到http://yourname.com

    确保在编辑配置文件后重新加载 nginx 服务器

    【讨论】:

      【解决方案2】:

      它被称为 IP 规范问题 您希望将您的 IP 地址重定向到您的域名

      为此,您可以在 nginx 服务器块中添加以下代码或在 nginx 配置中添加额外的服务器块

      server {
              listen 80;
              server_name www.example.com example.com 192.168.xxx.xx;
              return 301 https://www.example.com$request_uri;
      }
      

      我在我的服务器上使用这个配置;如果您尝试通过 HTTP 连接到 VPS 的 IP 地址,它将被重定向到我的主网站。

      【讨论】:

        【解决方案3】:

        我在 ispconfig 中解决了从 ip 地址 http/https 重定向:

        server {
            listen *:80;
        
            listen *:443 ssl http2;
            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
            ssl_certificate /var/www/clients/client1/web1/ssl/domain.example-le.crt;
            ssl_certificate_key /var/www/clients/client1/web1/ssl/domain.example-le.key;
        
            server_name    xxx.xxx.xxx.xxx;
            return         301 https://domain.example;
        }
        

        【讨论】:

          【解决方案4】:
          server {
          listen *:80;
          listen *:443 ssl http2;
          
          *#Required TLS Version*
          ssl_protocols TLSv1.1 TLSv1.2;
          
          *#SSL Certificate Path*
          ssl_certificate /etc/nginx/keyfiles/ssl_certificate.crt;
          ssl_certificate_key /etc/nginx/keyfiles/ssl_cert.key;
          
          *#IP Address*
          server_name    000.111.222.333;
          
          *#Domain Name to be redirected*
          return         301 https://www.domainname.com/;
          }
          

          【讨论】:

            猜你喜欢
            • 2021-03-25
            • 2018-01-05
            • 2020-04-07
            • 2021-08-27
            • 1970-01-01
            • 2021-11-23
            • 2016-01-09
            • 2019-10-08
            相关资源
            最近更新 更多