Nginx 屏蔽请求方式(PUT\DELETE)

来自ling
跳转至: 导航搜索

https://www.oschina.net/question/12_26843

upstream tomcat {
ip_hash;
server 192.168.2.187:8080;
}

location ~* /html {

if ($request_method = PUT ) {

return 403;

}

if ($request_method = DELETE ) {

return 403;

}

if ($request_method = POST ) {

return 403;

}

proxy_method GET;

proxy_pass http://tomcat;

}


#user  nobody;
worker_processes  auto;
worker_rlimit_nofile 100000;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  10240;
	multi_accept on;
}


http {
    include       mime.types;
	server_names_hash_bucket_size 128; 
    default_type  application/octet-stream;
    limit_conn_zone $binary_remote_addr zone=perip:10m;
	limit_conn_zone $server_name zone=perserver:10m;
	limit_req_zone $binary_remote_addr zone=allips:20m rate=50r/s;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  0;

    gzip on;
    gzip_min_length 1k;
    gzip_buffers 32 4k;
    gzip_http_version 1.1;
    gzip_comp_level 5;
    gzip_types  text/plain
            text/xml
            text/css
            text/csv
            application/xml
            application/javascript
            application/x-javascript
            application/json
            application/octet-stream
            application/x-font-ttf
            application/rtf;
    gzip_vary on;
	
 upstream  train{
    ip_hash;
	server 127.0.0.1:8091;
}

 upstream  tax-cor{
    ip_hash;
	server 127.0.0.1:10020;
}

 upstream  exer{
    ip_hash;
	server 127.0.0.1:8092;
}

upstream  taxlegal_test{
    ip_hash;
	server 127.0.0.1:8091;
}

 upstream  tr_pre{
    ip_hash;
	server 10.172.64.201:9080;
}

 upstream  tr_west{
    ip_hash;
	server 10.172.64.201:9083;
}

 upstream  ges_bak{
    ip_hash;
	server 10.172.64.201:9084;
}

upstream  ges_test{
    ip_hash;
	server 127.0.0.1:7071;
}
upstream  ges_preproduction{
    ip_hash;
	server 127.0.0.1:7073;
}
upstream  ges_stress{
    ip_hash;
	server 127.0.0.1:7071;
}
upstream  ges_urgent{
    ip_hash;
	server 127.0.0.1:7071;
}

upstream  ges11{
    ip_hash;
	server 127.0.0.1:8091;
}

upstream  stress_test{
    ip_hash;
	server 127.0.0.1:7071;
}
proxy_cache_path temp/ 
  levels=1:2 
  keys_zone=fonts_cache:1m
  inactive=1d
  max_size=256m;

map $http_host $this_host {
    "" $host;
    default $http_host;
}

map $http_x_forwarded_proto $the_scheme {
     default $http_x_forwarded_proto;
     "" $scheme;
}

map $http_x_forwarded_host $the_host {
    default $http_x_forwarded_host;
    "" $this_host;
}

map $http_upgrade $proxy_connection {
  default upgrade;
  "" close;
}

proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $proxy_connection;
proxy_set_header X-Forwarded-Host $the_host;
proxy_set_header X-Forwarded-Proto $the_scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
 

    server {
    listen 0.0.0.0:443 ssl;
    listen [::]:443 ssl default_server;
    server_tokens off;
	client_body_timeout 10s;
    client_header_timeout 10s;
    large_client_header_buffers 4 8k;
	client_header_buffer_size 1k;
	
	add_header Set-Cookie "HttpOnly";
	add_header Set-Cookie "Secure";
    add_header X-Frame-Options SAMEORIGIN;
	
	limit_conn perip 500;
	limit_conn perserver 10000;
    #if ($request_method = PUT ) {
    #             return 403;
    #}
    #if ($request_method = DELETE ) {
     #        return 403;
    #}
 
	ssl_certificate      C:\\server\\nginx-1.14.0\\ssl\\lee.crt;
    ssl_certificate_key  C:\\server\\nginx-1.14.0\\ssl\\lee.key;
	ssl_session_cache    shared:SSL:1m;
    ssl_session_timeout  5m;
    
    ssl_ciphers  HIGH:!aNULL:!MD5;
    ssl_prefer_server_ciphers  on;

       
 
		charset utf-8;
		location /train{
        proxy_pass  http://train;
		proxy_cookie_path / "/train; HTTPOnly; Secure;";
        proxy_http_version 1.1;
        proxy_set_header   Connection       "";
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
		proxy_redirect http:// $scheme://;
		proxy_connect_timeout 6s;
        proxy_send_timeout 600s;
        proxy_read_timeout 600s;
        proxy_buffer_size 4k;
        proxy_buffers 32 4k;
        proxy_busy_buffers_size 64k;
        client_max_body_size 1000m;
        client_body_buffer_size 128k;
       }
	   
	   location ^~/tax-cor/{
        proxy_pass  http://tax-cor/;		 
        proxy_http_version 1.1;
        proxy_set_header   Connection       "";
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
		proxy_redirect http:// $scheme://;
		proxy_connect_timeout 6s;
        proxy_send_timeout 600s;
        proxy_read_timeout 600s;
        proxy_buffer_size 4k;
        proxy_buffers 32 4k;
        proxy_busy_buffers_size 64k;
        client_max_body_size 1000m;
        client_body_buffer_size 128k;
       }
	   
	   location /exer{
        proxy_pass  http://exer;
		proxy_cookie_path / "/exer; HTTPOnly; Secure;";
        proxy_http_version 1.1;
        proxy_set_header   Connection       "";
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
		proxy_redirect http:// $scheme://;
		proxy_connect_timeout 6s;
        proxy_send_timeout 600s;
        proxy_read_timeout 600s;
        proxy_buffer_size 4k;
        proxy_buffers 32 4k;
        proxy_busy_buffers_size 64k;
        client_max_body_size 1000m;
        client_body_buffer_size 128k;
       }
	   
	   location /taxlegal_test{
        proxy_pass  http://taxlegal_test;
		proxy_cookie_path / "/taxlegal_test; HTTPOnly; Secure;";
        proxy_http_version 1.1;
        proxy_set_header   Connection       "";
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
		proxy_redirect http:// $scheme://;
		proxy_connect_timeout 6s;
        proxy_send_timeout 600s;
        proxy_read_timeout 600s;
        proxy_buffer_size 4k;
        proxy_buffers 32 4k;
        proxy_busy_buffers_size 64k;
        client_max_body_size 1000m;
        client_body_buffer_size 128k;
       }
	   
	   location /tr_pre{
        proxy_pass  http://tr_pre;
		proxy_cookie_path / "/tr_pre; HTTPOnly; Secure;";
        proxy_http_version 1.1;
        proxy_set_header   Connection       "";
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
		proxy_redirect http:// $scheme://;
		proxy_connect_timeout 6s;
        proxy_send_timeout 600s;
        proxy_read_timeout 600s;
        proxy_buffer_size 4k;
        proxy_buffers 32 4k;
        proxy_busy_buffers_size 64k;
        client_max_body_size 1000m;
        client_body_buffer_size 128k;
       }
	   
	   location /ges_test{
        proxy_pass  http://ges_test;
		proxy_cookie_path / "/ges_test; HTTPOnly; Secure;";
        proxy_http_version 1.1;
        proxy_set_header   Connection       "";
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
		proxy_redirect http:// $scheme://;
		proxy_connect_timeout 6s;
        proxy_send_timeout 600s;
        proxy_read_timeout 600s;
        proxy_buffer_size 4k;
        proxy_buffers 32 4k;
        proxy_busy_buffers_size 64k;
        client_max_body_size 1000m;
        client_body_buffer_size 128k; 
	 
       }
	   
	    location /stress_test{
        proxy_pass  http://stress_test;
		proxy_cookie_path / "/; HTTPOnly; Secure;";
        proxy_http_version 1.1;
        proxy_set_header   Connection       "";
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;	
		proxy_connect_timeout 6s;
        proxy_send_timeout 60s;
        proxy_read_timeout 60s;
        proxy_buffer_size 4k;
        proxy_buffers 32 4k;
        proxy_busy_buffers_size 64k;
        client_max_body_size 1000m;
        client_body_buffer_size 128k;
       }
	  
	     location /ges_preproduction{
        proxy_pass  http://ges_preproduction;
		proxy_cookie_path / "/ges_preproduction; HTTPOnly; Secure;";
        proxy_http_version 1.1;
        proxy_set_header   Connection       "";
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
		proxy_redirect http:// $scheme://;
		proxy_connect_timeout 6s;
        proxy_send_timeout 600s;
        proxy_read_timeout 600s;
        proxy_buffer_size 4k;
        proxy_buffers 32 4k;
        proxy_busy_buffers_size 64k;
        client_max_body_size 1000m;
        client_body_buffer_size 128k; 
	 
       }
	   
	    location /ges_stress{
        proxy_pass  http://ges_stress;
		proxy_cookie_path / "/; HTTPOnly; Secure;";       
        proxy_http_version 1.1;
        proxy_set_header   Connection       "";
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
		proxy_redirect http:// $scheme://;
		proxy_connect_timeout 6s;
        proxy_send_timeout 600s;
        proxy_read_timeout 600s;
        proxy_buffer_size 4k;
        proxy_buffers 32 4k;
        proxy_busy_buffers_size 64k;
        client_max_body_size 1000m;
        client_body_buffer_size 128k;
       }
	   
	   
	   
	   location /ges_urgent{
        proxy_pass  http://ges_urgent;
		proxy_cookie_path / "/ges_urgent; HTTPOnly; Secure;";        
        proxy_http_version 1.1;
        proxy_set_header   Connection       "";
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
		proxy_redirect http:// $scheme://;
		proxy_connect_timeout 6s;
        proxy_send_timeout 600s;
        proxy_read_timeout 600s;
        proxy_buffer_size 4k;
        proxy_buffers 32 4k;
        proxy_busy_buffers_size 64k;
        client_max_body_size 1000m;
        client_body_buffer_size 128k;
       }
	   
	   location /tr_west{
        proxy_pass  http://tr_west;
		#proxy_cookie_path / "/ges_urgent; HTTPOnly; Secure;";        
        proxy_http_version 1.1;
        proxy_set_header   Connection       "";
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
		proxy_redirect http:// $scheme://;
		proxy_connect_timeout 6s;
        proxy_send_timeout 600s;
        proxy_read_timeout 600s;
        proxy_buffer_size 4k;
        proxy_buffers 32 4k;
        proxy_busy_buffers_size 64k;
        client_max_body_size 1000m;
        client_body_buffer_size 128k;
       }
	   
	   location /ges_bak {
        proxy_pass  http://ges_bak;
		#proxy_cookie_path / "/ges_bak;HTTPOnly; Secure;";        
        proxy_http_version 1.1;
        proxy_set_header   Connection       "";
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
		proxy_redirect http:// $scheme://;
		proxy_connect_timeout 6s;
        proxy_send_timeout 600s;
        proxy_read_timeout 600s;
        proxy_buffer_size 4k;
        proxy_buffers 32 4k;
        proxy_busy_buffers_size 64k;
        client_max_body_size 1000m;
        client_body_buffer_size 128k;
       }
	    
	 location / {
         root   html/dist;
         index  index.html index.htm;
     }
	 
	 location ~ ^/(images|javascript|js|css|flash|media|static)/  {
          root       html/dist/;
          access_log  off;
          expires     30d;
        }	

		
	   location /platform {
         proxy_pass	https://10.172.64.204/index.html;
     }
	 
     location /tax-main {
            proxy_pass	http://10.172.64.204:8085/tax-main;
        }
    location /nginx_status {
         stub_status   on;
         access_log  off;
     }
    }


 


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}