tomcat9使用nginx配置反向代理时出现:The character [_] is never valid in a domain name

  • 下面是浏览器访问错误日志
HTTP Status 400 – 错误的请求
Type 异常报告
​
消息 The character [_] is never valid in a domain name.
​
描述 由于被认为是客户端对错误(例如:畸形的请求语法、无效的请求信息帧或者虚拟的请求路由),服务器无法或不会处理当前请求。
​
Exception
​
java.lang.IllegalArgumentException: The character [_] is never valid in a domain name.
  org.apache.tomcat.util.http.parser.HttpParser$DomainParseState.next(HttpParser.java:963)
  org.apache.tomcat.util.http.parser.HttpParser.readHostDomainName(HttpParser.java:859)
  org.apache.tomcat.util.http.parser.Host.parse(Host.java:71)
  org.apache.tomcat.util.http.parser.Host.parse(Host.java:45)
  org.apache.coyote.AbstractProcessor.parseHost(AbstractProcessor.java:289)
  org.apache.coyote.http11.Http11Processor.prepareRequest(Http11Processor.java:807)
  org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:384)
  org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
  org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860)
  org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1589)
  org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  java.lang.Thread.run(Thread.java:748)
Note 主要问题的全部 stack 信息可以在 server logs 里查看
​
Apache Tomcat/9.0.26

可以看出上图中,character [_]这个非常关键,于是 我去nginx的配置文件中查找_

  • 下面是我原有的nginx.conf配置文件
upstream item_pool {
        server 1x.xxx.xx.xxx:xx weight=1;
        server 1x.xxx.xx.xx:xx weight=1;
    }
​
   server {
        listen          9090;
        server_name     127.0.0.1;
        location / {
                proxy_http_version      1.1;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header        REMOTE-HOST $remote_addr;
                proxy_pass              http://item_pool;
                proxy_next_upstream     off;
        #       # proxy_redirect                off;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
  }

发现在 upstream item_pool,有_,将_去掉后,使用nginx -s reload重新加载配置文件,访问对应的端口,果然成功,记录一下,方便日后查询使用
tomcat9使用nginx配置反向代理时出现:The character [_] is never valid in a domain name_第1张图片

你可能感兴趣的:(nginx)