king71 发表于 2016-12-26 10:32:04

nginx请求转发备注

我想根据请求的地址来做转发:
比如请求:www.mydomon.com/scm_sample 那么扔到另一台机器上.




server {
    listen       80;
    server_namewwww.hupun.com;

    #charset koi8-r;

    #access_loglogs/host.access.logmain;

    location ~ ^/scm/(images|pages|javascript|js|css|flash|media|static)/{
                root    /home/apache-tomcat-7.0.22/webapps;
      #      expires 30d;
    }

    location ~ ^/scm/(.*.jpg|.*.gif|.*.png|.*.bmp)/{
                root    /home/apache-tomcat-7.0.22/webapps;
    }

    location /scm {
      index sys.index.d;
      proxy_pass http://127.0.0.1:8080$request_uri;
    }

    location /scm_sample {
            set $fixed_destination $http_destination;
            if ($http_destination ~* ^https(.*)$){
               set $fixed_destination http$1;
            }
            proxy_set_header      Host $host;
            proxy_set_header      X-Real-IP $remote_addr;
            proxy_set_header      Destination $fixed_destination;
            proxy_pass            http://111.11.111.111$request_uri;

    }


------------------------------根据访问地址确定访问应用----------------------------------
server{
   listen80;
   server_nametcrm.hupun.com;

   location / {
             proxy_pass      http://127.0.0.1:5180/;
             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 /crm.open {
      index index.html;
      proxy_pass      http://127.0.0.1:8380/;
             proxy_set_header   Host             $host;
             proxy_set_header   X-Real-IP      $remote_addr;
             proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
   }

}
页: [1]
查看完整版本: nginx请求转发备注