• 请不要在回答技术问题时复制粘贴 AI 生成的内容
newbeexw
V2EX  ›  程序员

急,关于 nginx 反代集群问题, nginx——3 台 tomcat。

  •  
  •   newbeexw · Jan 28, 2019 · 2490 views
    This topic created in 2670 days ago, the information mentioned may be changed or developed.

    tomcat 是 192.168.0.242:18001/index.action 的服务。直接访问 tomcat 地址没事。

    upstream tomcat {

      server 192.168.0.242:18001; 
      server 192.168.0.242:18002;
      server 192.168.0.242:18003; 
     }
    

    server { listen 80; server_name localhost; access_log logs/access.log; location / {

                proxy_set_header Host $proxy_host;
                proxy_set_header         REMOTE-HOST $remote_addr;
                proxy_set_header         X-Real-IP $remote_addr;
                proxy_set_header         X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass               http://tomcat;
                client_max_body_size     10m;
                client_body_buffer_size  256k;
                proxy_connect_timeout    600;
                proxy_send_timeout       600;
                proxy_read_timeout       600;
                proxy_buffer_size        32k;
                proxy_buffers            4 64k;
                proxy_busy_buffers_size  128k;
                proxy_temp_file_write_size 512k;
    

    }

    然而访问我 localhost,却自动跳转 tomcat/index.action 报错。我该怎么访问 tomcat 集群。

    8 replies    2019-01-28 13:43:19 +08:00
    lazyfighter
        1
    lazyfighter  
       Jan 28, 2019
    server_name 是域名 tomcat 是啥
    lotmany
        2
    lotmany  
       Jan 28, 2019
    应用内部不要重定向跳转 或者 nginx 改重定向的跳转 搜 nginx redirect
    newbeexw
        3
    newbeexw  
    OP
       Jan 28, 2019
    @lazyfighter tomcat 是 nginx upstream 的名称
    newbeexw
        4
    newbeexw  
    OP
       Jan 28, 2019
    @sunsulei 做一个轮训的 tomcat 集群,这可咋办
    lotmany
        5
    lotmany  
       Jan 28, 2019
    @newbeexw 主要原因还是应用做了重定向 , 配置 nginx_redirect 呢. 只要保证重定向后的地址还是 localhost 就行了.
    lotmany
        6
    lotmany  
       Jan 28, 2019
    @newbeexw 还是贴出 F12 的 network 里的跳转过程吧, 看看 302 的 Location 是啥.
    hcymk2
        7
    hcymk2  
       Jan 28, 2019
    tomcat 这个地址你写了 hosts 了么?
    Lax
        8
    Lax  
       Jan 28, 2019
    proxy_set_header Host $proxy_host;
    这个写法很不常规啊,跳转到 tomcat 是因为 $proxy_host 的值是 `tomcat`。
    一般也就用 $host 或者 $http_host。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5037 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 09:33 · PVG 17:33 · LAX 02:33 · JFK 05:33
    ♥ Do have faith in what you're doing.