【问题标题】:nginx redirect different roots to different portsnginx将不同的根重定向到不同的端口
【发布时间】:2021-03-18 19:24:19
【问题描述】:

在检查文档和 stackoverflow 数小时后,我仍然无法弄清楚如何做到这一点。

这是我的 nginx.conf:

http {
  upstream backend {
      least_conn;
      server 192.168.77.81:8078 weight=4;
      server 192.168.77.231:8078 weight=7 max_fails=1 fail_timeout=1s;
  }

  upstream static_backend {
      server 192.168.77.81:8079;
  }

  server {
      listen       8068;
      access_log off;
      error_log off;
      location / {
          proxy_pass http://backend;
          proxy_set_header   Host    $host;
          proxy_set_header   X-Real-IP   $remote_addr;
          proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
      }
      location /static/ {
          proxy_pass http://192.168.77.81:8079;
      }
  }
}

events {}

我想将所有http://192.168.77.81:8068/static 重定向到http://192.168.77.81:8079/static

但这一切都会导致 301 Moved Permanently 或 http://192.168.77.81:8078/static

这让我发疯了

我也尝试过别名和root,但它们都不起作用

任何建议将不胜感激!

【问题讨论】:

    标签: nginx redirect routes reverse-proxy


    【解决方案1】:

    只需做 proxy_pass ~ /static

    这个“~”花了我几个小时......

    【讨论】:

      猜你喜欢
      • 2015-03-15
      • 2014-04-01
      • 1970-01-01
      • 2019-11-04
      • 2013-10-01
      • 2012-06-19
      • 2015-03-15
      • 2019-09-25
      • 1970-01-01
      相关资源
      最近更新 更多