【问题标题】:NginX reverse proxy without pass pathNginX 反向代理,没有传递路径
【发布时间】:2022-02-01 00:29:20
【问题描述】:

我想通过这种行为在 Nginx 中使用反向代理的“proxy_pass”:

  • 当有人尝试访问“https://myweb.com”时,proxypass 会重定向到“https://myproxyweb.com”
  • 当有人尝试访问“https://myweb.com/foo”时,proxypass 会重定向到“https://myproxyweb.com”

总之,我想将所有路径代理传递到我的代理网站的根目录。

我有这个,但不起作用:

location / {
    proxy_pass https://myproxyweb.com/;
    }

它不起作用,因为当我尝试转到“https://myweb.com/foo”时,Nginx 尝试显示“https://myproxyweb.com/foo”

【问题讨论】:

  • 使用location / { rewrite ^ / break; proxy_pass https://myproxyweb.com; }

标签: nginx nginx-reverse-proxy nginx-location


【解决方案1】:

试试:

server
{
  listen 443 ssl http2:
  server_name myweb.com;

  # TO DO: Configure SSL certificate

  location /
  {
    return 301 https://myproxyweb.com$is_args$args;
  }

  location /foo
  {
    return 301 https://myproxyweb.com;
  }
}

server
{
  listen 443 ssl http2;
  server_name myproxyweb.com;

  # TO DO: Configure SSL certificate

  ...

}

【讨论】:

    猜你喜欢
    • 2013-06-29
    • 2023-03-24
    • 1970-01-01
    • 1970-01-01
    • 2018-03-24
    • 2019-04-16
    • 2019-08-05
    • 1970-01-01
    • 2012-06-10
    相关资源
    最近更新 更多