03 |
server
192.168.2.187:8080; |
08 |
if ($request_method
= PUT ) { |
14 |
if ($request_method
= DELETE ) { |
20 |
if ($request_method
= POST ) { |
当路径包含/html的时候,则代理到server后端进行请求数据。这里屏蔽了PUT,DELETE,POST方法,只是使用了GET,主要目的是为了安全性,因为DELETE,POST,PUT是可以修改数据的。
或者:
07 |
if ($request_filename
~ /test/index.html) { |
09 |
rewrite
^/(.*) /index.html; |
nginx禁止访问txt|doc文件
方法一:全局设置,禁止访问任何以后缀txt|doc的文件
1 |
location
~* \.(txt|doc)$ { |
方法二:只禁止访问某目录下的txt|doc
1 |
location
~* \.(txt|doc)$ { |
2 |
if (-f
$request_filename) { |
nginx禁止某中浏览器访问:#浏览器类型可从日志得知。
4 |
server_name
test.domain.com; |
5 |
index
index.php index.html; |
7 |
if ( $http_user_agent ~* "MSIE
6.0" )
{ |
设置目录执行权限
在windows+iis下,可以设置上传目录,类似:upload,uploadfile,attachments,这样的目录下面无脚本执行权限,从而防止非法用户上传脚本得到webshell
nginx上也很简单,我们使用location 如下:
1 |
location
~ ^/upload/.*\.(php|php5)$ |
其中upload换为你要设置的目录名字
这条规则的含义是匹配请求连接中开头是/upload/,中间匹配任意字符,结尾匹配.php或者.php5的页面,最后利用deny all禁止访问,这样就防止了上传目录的脚本执行权限
## Only allow these request methods (GET|HEAD|POST)
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 444; }