nginx学习

nginx的Status Code499
rfc2616中,http status code 400~500间的错误码仅定义到了417,nginx自己定义的495~499。
495 https certificate error
496 https no certificate
497 http to https
498 canceled
499 client has closed connection


access.log 设为off有什么好处?

proxy_intercept_errors 为on 表示 nginx按照原response code 输出,后端是404,就是404. 还有另外一点,这个变量开启后,我们才能自定义错误页面。


八、 Nginx 防盗链

1. 针对不同的文件类型
#Preventing hot linking of images and other file types
location ~* ^.+.(gif|jpg|png|swf|flv|rar|zip)$ {
valid_referers none blocked server_names *.linuxtone.org linuxtone.org http://localhost baidu.com;
if ($invalid_referer) {
rewrite ^/ ;
# return 403;
}
}
2. 针对不同的目录
location /img/ {
root /data/www/wwwroot/bbs/img/;
valid_referers none blocked server_names *.linuxtone.org http://localhost baidu.com;
if ($invalid_referer) {
rewrite ^/ ;
#return 403;
}
}
3. 同实现防盗链和expires的方法
#Preventing hot linking of images and other file types
location ~* ^.+.(gif|jpg|png|swf|flv|rar|zip)$ {
valid_referers none blocked server_names *.linuxtone.org linuxtone.org http://localhost ;
if ($invalid_referer) {
rewrite ^/ ;
}
access_log off;
root /data/www/wwwroot/bbs;
expires 1d;
break;
}
3. Nginx 如何不记录部分日志
日志太多,每天好几个G,少记录一些,下面的配置写到server{}段中就可以了
location ~ .*.(js|jpg|JPG|jpeg|JPEG|css|bmp|gif|GIF)$
{
access_log off;
}


但是,如果我把alias的配置改成:

location /abc/ {
alias /home/html/def/;
}

那么nginx将会从/home/html/def/取数据,这段配置还不能直接使用root配置,如果非要配置,只有在/home/html/下建立一个 def->abc的软link(快捷方式)了。

一般情况下,在location /中配置root,在location /other中配置alias是一个好习惯。


现在我们来说说上面提到的 internal , internal 顾名思义就是指的 Nginx 的内部处理指令, 引用官方的解释就是"表明 只有内部的请求才能使用的.例如请求返回404错误. "而到这里 , 显而易见的是header('X-Accel-Redirect: /download/file.exe');是向服务器提交了一个内部请求,然后Nginx自动将此连接转向到实际的地址.而经过我和头儿使用 firefox 的 firedebug 测试,也确实没有捕捉到 X-Accel-Redirect 头信息!所以我们只是猜想,可能Nginx在发送数据之前先对数据进行了检验,然后检测到这些信息就自动过滤,提交到内部处理.因为没见过源码,所以也只 能说是猜想!不过其实想想也明白了,如果这些头信息被捕捉 一些关键信息暴露 那么这个特性的安全性就会大大折扣!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值