从端口80到其他端口的nginx代理

从端口80到其他端口的nginx代理,nginx,docker,Nginx,Docker,我的目标是重定向http://localhost/web1至http://localhost:5000/。我是nginx的新手,日志给了我很多信息。localhost:5000正在运行。我在docker上运行这个,如果它可能是问题的一部分(nginx:alpine) 配置: server { listen 80; server_name localhost; location / { root /usr/share/nginx/html; inde

我的目标是重定向
http://localhost/web1
http://localhost:5000/
。我是nginx的新手,日志给了我很多信息。localhost:5000正在运行。我在docker上运行这个,如果它可能是问题的一部分(nginx:alpine)

配置:

server {
  listen       80;
  server_name  localhost;

  location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
  }

  # redirect server error pages to the static page /50x.html
  #
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
    root   /usr/share/nginx/html;
  }

  location /web1 {
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:5000/;
  }

  location /web2 {
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:5001/;
  }

}

我在nginx中使用for
rewrite
用于重定向目的,我认为您应该尝试以下方法:

location /web1 {
    rewrite  ^/(.*)$  $scheme://127.0.0.1:5000/$1  permanent;
}

在我的centos机器上,它工作正常,希望它能帮助你

谢谢,看起来它能满足我的需要。我很快就会接受这个答案,看看它是否被社会所接受。因为我对nginx太陌生了
server {
  listen       80;
  server_name  localhost;

  location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
  }

  # redirect server error pages to the static page /50x.html
  #
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
    root   /usr/share/nginx/html;
  }

  location /web1 {
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:5000/;
  }

  location /web2 {
    proxy_set_header Host $host;
    proxy_pass http://127.0.0.1:5001/;
  }

}
location /web1 {
    rewrite  ^/(.*)$  $scheme://127.0.0.1:5000/$1  permanent;
}