api.ufo.conf 2.49 KB
server {

    listen 80;

    ## for proxy
    proxy_http_version 1.1;
    proxy_set_header Connection ""; 
    
	
    server_name  2.yohobuy.com  ufoapi.yohoops.org;

    
    access_log  /Data/logs/nginx/ufo_access.log  fenxi;
    error_log   /Data/logs/nginx/ufo_error.log;

	
    set $real_ip "";
    set $request_api_method "-";
    set $request_udid "-";
    set $request_uid "-";

    set_by_lua_file $real_ip conf/setup.lua;
    log_by_lua_file  conf/lua/set_log_params.lua;

 #   set_by_lua_file $real_ip conf/setup.lua;
	
#    access_by_lua_file  'conf/lua/limit_api_flow.lua';
	

#################### reject http HEAD & status check / .ico quest ######### 

	# HEAD REQUEST RETURN 405
    if ( $request_method = HEAD ) {
     	 return 200;
    }

   # redirect to https
   set $rewite 0;
    if ($http_x_client_proto = 'http') {
        set $rewite 1;
    }
    if ($http_x_forwarded_proto = 'http') {
        set $rewite 1;
    }
    if ($request_method ~* POST) {
         set $rewite 0;
    }
   

	# nginx status check
    location = /status_check {
           default_type text/html;
           return 200  'server is ok!';  
    }
   
    # cdn check 
     location = /test.html {
       return 200;
     }
   
    location  = /favicon.ico {
         log_not_found off;
         access_log off;  
    }


#################### begin  match  2.yohobuy.com #########################
    
  #  location / {
   #     rewrite_by_lua_file conf/redirect.lua;
   # }

#################### end  match  2.yohobuy.com #########################

   location  / {
        limit_req zone=limit_ufo burst=50 nodelay;
        proxy_redirect off;
        proxy_pass  http://ufogateway/ufo-gateway/;
        proxy_set_header   X-Real-IP  $real_ip;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   Accept-Encoding "gzip";
        proxy_http_version  1.1;
        proxy_set_header   Connection "";
        proxy_set_header Host $host;
    }

   # forward to node app
    location ^~ /mapp/ {
       #redirect to 301 if get
       if ($rewite = 1) {
        return 301  https://$host$request_uri ;
       }
        proxy_redirect off;
        proxy_pass  http://ufomapp/mapp/;
        proxy_set_header   Host   "2.yohobuy.com";
        proxy_set_header   X-Real-IP  $remote_addr;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   Accept-Encoding "gzip";
    }


  location ~* .(txt)$ {
        root /Data/local/openresty-1.9.15.1/nginx/html;
    }
  
}