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
;
}
|
當路徑包含/html的時候,則代理到server后端進行請求數據。這里屏蔽了PUT,DELETE,POST方法,只是使用了GET,主要目的是為了安全性,因為DELETE,POST,PUT是可以修改數據的。
或者:
limit_except GET {
allow 192.168.1.1;
deny all;
if ($request_filename ~ /test/index .html) {
# return 404;
rewrite ^/(.*) /index .html;
}
};
|
nginx禁止訪問txt|doc文件
方法一:全局設置,禁止訪問任何以后綴txt|doc的文件
location ~* \.(txt|doc)$ {
deny all;
}
方法二:只禁止訪問某目錄下的txt|doc
location ~* \.(txt|doc)$ {
if (-f $request_filename) {
root html/job;
break;
}
}
nginx禁止某中瀏覽器訪問:#瀏覽器類型可從日志得知。
server
{
listen 80;
server_name test.domain.com;
index index.php index.html;
root /opt/nginx/html/;
if ( $http_user_agent ~* "MSIE 6.0" ) {
return 403;
}
設置目錄執行權限
在windows+iis下,可以設置上傳目錄,類似:upload,uploadfile,attachments,這樣的目錄下面無腳本執行權限,從而防止非法用戶上傳腳本得到webshell
nginx上也很簡單,我們使用location 如下:
location ~ ^/upload/.*\.(php|php5)$
{
deny all;
}
其中upload換為你要設置的目錄名字
這條規則的含義是匹配請求連接中開頭是/upload/,中間匹配任意字符,結尾匹配.php或者.php5的頁面,最后利用deny all禁止訪問,這樣就防止了上傳目錄的腳本執行權限。
轉自:http://www.512873.com/archives/471.html