• nginx 设置ip地址访问,但是设置域名访问不了


    一、导语

      在Nginx的设置过程中,ip地址能正常访问的,但是把ip地址转换成域名,就访问不了了,这个是怎么回事呢?今天来探讨一下

    二、设置ip地址做负载均衡

    2.1、server端

    server {
            listen       80;
            server_name  192.168.1.1; #设置为ip地址
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
    
            location / {
               proxy_read_timeout 1200;
               proxy_send_timeout 1200;
               proxy_connect_timeout 1200;
               proxy_set_header  X-Real-IP  $remote_addr;
               proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
               proxy_set_header Host $http_host;
               proxy_redirect off;
               proxy_pass http://192.168.1.1/;
    
            }
    
     }
    

    2.2、upstream端

    upstream 192.168.1.1{
            #tomcat1002
            server 192.168.1.1:8081 weight=50;
            #tomcat1001
            server 192.168.1.1:8080 weight=50;
    }
    

    然后再Nginx -t 测试一下看能是否访问

    [root@VM_0_3_centos server]# nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    

    三、ip地址能访问,但是域名访问不了

    在客户端也做了ping了,域名指向命名是ip地址就是访问不了,原来,Nginx优先解析自己的Nginx.conf配置文件,所以先解析自己的,自己的配置文件如下:

    所以我们把这部分删掉,在include server/*  自己的配置文件

  • 相关阅读:
    自适应行高
    IOS各类问题
    KVC
    数据模型的构建及懒加载数据
    NSBundle
    九宫格布局获取行/列索引
    QLineEdit
    QLabel
    排序算法
    SpringBoot配置文件-yaml
  • 原文地址:https://www.cnblogs.com/zhangqigao/p/8214325.html
Copyright © 2020-2023  润新知