upstream
tomcat { |
02 |
ip_hash; |
03 |
server
192.168.2.187:8080; |
04 |
} |
05 |
06 |
location
~* /html { |
07 |
08 |
if ($request_method
= PUT ) { |
09 |
10 |
return 403; |
11 |
12 |
} |
13 |
14 |
if ($request_method
= DELETE ) { |
15 |
16 |
return 403; |
17 |
18 |
} |
19 |
20 |
if ($request_method
= POST ) { |
21 |
22 |
return 403; |
23 |
24 |
} |
25 |
26 |
proxy_method
GET; |
27 |
28 |
proxy_pass
http: //tomcat; |
29 |
30 |
} |
當路徑包含/html的時候,則代理到server後端進行請求數據。這裏屏蔽了PUT,DELETE,POST方法,只是使用了GET,主要目的是爲了安全性,因爲DELETE,POST,PUT是可以修改數據的。
或者:
01 |
limit_except
GET { |
02 |
allow
192.168.1.1; |
03 |
deny
all; |
04 |
} |
05 |
06 |
07 |
if ($request_filename
~ /test/index.html) { |
08 |
#
return 404; |
09 |
rewrite
^/(.*) /index.html; |
10 |
}; |
nginx禁止訪問txt|doc文件
1 |
location
~* \.(txt|doc)$ { |
2 |
deny
all; |
3 |
} |
1 |
location
~* \.(txt|doc)$ { |
2 |
if (-f
$request_filename) { |
3 |
root
html/job; |
4 |
break ; |
5 |
} |
6 |
} |
1 |
server |
2 |
{ |
3 |
listen
80; |
4 |
server_name
test.domain.com; |
5 |
index
index.php index.html; |
6 |
root
/opt/nginx/html/; |
7 |
if ( $http_user_agent ~* "MSIE
6.0" )
{ |
8 |
return 403; |
9 |
} |
nginx上也很簡單,我們使用location 如下:
1 |
location
~ ^/upload/.*\.(php|php5)$ |
2 |
{ |
3 |
deny
all; |
4 |
} |
其中upload換爲你要設置的目錄名字
這條規則的含義是匹配請求連接中開頭是/upload/,中間匹配任意字符,結尾匹配.php或者.php5的頁面,最後利用deny all禁止訪問,這樣就防止了上傳目錄的腳本執行權限
## Only allow these request methods (GET|HEAD|POST)
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 444; }