Nginx代理将附加请求参数传递给上游

时间:2014-04-24 03:24:28

标签: nginx proxy

这是我的网站conf -

upstream demo {
       server server1:31337;
       server server2:31338;
       server server3:31339;
       server server4:31340;
       keepalive 64;
    }

server {
       listen         80;
       server_name    www.site.org;
       rewrite        ^ https://$server_name$request_uri? permanent;

       location / {
          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;
          proxy_set_header   Connection "";
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection $connection_upgrade;
          proxy_cache one;
          proxy_cache_key sfs$request_uri$scheme;
          proxy_pass         http://demo;
       }
}

我希望当我打开www.site.org时,它应该代理传递给任何上游服务器作为server2:31337 / mysite

如何追加/ mysite请求参数?

1 个答案:

答案 0 :(得分:0)

你能试试吗

  location / {
      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;
      proxy_set_header   Connection "";
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;
      proxy_cache one;
      proxy_cache_key sfs$request_uri$scheme;

      rewrite ^(.*)$ /mysite$1 break;

      proxy_pass         http://demo;
   }