今天在用nginx做反向代理时,由于一个tomcat下有多个应用,因此要在tomcat做域名绑定。tomcat启动后,通过域名+端口是可以访问到页面的,但是通过nginx转发后就不能访问了,因此tomcat配置是没有问题的。

然后看nginx配置文件,其中转发部分

server {
    listen       80;
    server_name  2018.cctvtzqc.com;

    location / {
        proxy_pass  http://192.168.0.3:8080;
   }
}

过于简单,还需要讲请求头一起发送给tomat才行,改之后:

server {
  listen       80;
  server_name  2018.cctvtzqc.com;

  location / {
    proxy_pass  http://192.168.0.3:8080;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }
}

加上红色部分就可以了。

相关文章:

  • 2021-11-19
  • 2021-10-17
  • 2021-10-25
  • 2022-12-23
  • 2021-10-02
  • 2022-12-23
猜你喜欢
  • 2021-11-12
  • 2022-01-07
  • 2021-07-05
  • 2021-08-28
  • 2021-11-02
相关资源
相似解决方案