如何将端口80重定向到nginx中的不同服务器?

时间:2017-01-10 19:06:29

标签: http redirect nginx reverse-proxy

在我的使用案例中,我想使用nginx作为反向代理将www.xyz.com/static重定向到www.abc.com。我有以下nginx配置,

worker_processes  1;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    keepalive_timeout  65;
    client_max_body_size 500M;
    #timeouts
    proxy_connect_timeout       600;
    proxy_send_timeout          600;
    proxy_read_timeout          600;
    send_timeout                600;
    upstream s-content {
      server abc.com;
      keepalive 64;
    }
    #
    # The default server
    #
    server {
      listen   80;
      server_name  rproxy;
      location /static {
            rewrite /(.*) /$1 break;
            proxy_pass http://s-content;
            proxy_redirect off;
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
            proxy_set_header   Host   $http_host;
            proxy_set_header   X-NginX-Proxy true;
            real_ip_header     X-Forwarded-For;
                real_ip_recursive  on;
            #proxy_set_header   Connection "";
            #proxy_http_version 1.1;
          }
        # redirect not found pages to the static page /404.html
        error_page  404  /404.html;
        location = /404.html {
            root   /usr/share/nginx/html;
        }
        # 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;
        }
    }
}

此服务器代理映射到xyz.com并侦听端口80.当我在abc.com/static中收到请求时,我想重定向到abc.com。但由于某些原因,重写无效。

有人可以帮我解决这个问题。我很感激帮助。

0 个答案:

没有答案