免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3313 | 回复: 2
打印 上一主题 下一主题

nginx.conf [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-04-11 17:35 |只看该作者 |倒序浏览
那位大哥给小弟提供一份关于“nginx.conf”详细配置资料啊!很多自己都不很清楚,里面的参数是干什么用的?
晓得在这里万分感谢了!

论坛徽章:
0
2 [报告]
发表于 2009-04-21 22:40 |只看该作者
和httpd.conf差不多,网上有很多文章,哪个参数看不懂,看哪个就可以,rewrite必须写在nginx.conf里

论坛徽章:
0
3 [报告]
发表于 2009-05-19 15:23 |只看该作者
1.Nginx 的一些可用的全局变量,可用做条件判断:

CODE:
$args

$content_length

$content_type

$document_root

$document_uri

$host

$http_user_agent

$http_cookie

$limit_rate

$request_body_file

$request_method

$remote_addr

$remote_port

$remote_user

$request_filename

$request_uri

$query_string

$scheme

$server_protocol

$server_addr

$server_name

$server_port

$url

2.Nginx Redirect

将所有chinaunix.net与abc.chinaunix.net域名全部自跳转到www.chinaunix.net 的代码

server

   {

            listen    80;

            server_name   chinaunix.net abc.chinaunix.net;

            index index.html index.php;

            root   /data/www/wwwroot;

            if ($http_host !~ "^www\.chinaunix\.net$") {

                      rewrite   ^(.*) http://www.chinaunix.net$1 redirect;

                }

            

            ........................

   }

3.Nginx 目录自动加斜线

if (-d $request_filename){

          rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;

   }

4.Nginx 防盗链

#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 http://localhost baidu.com;

if ($invalid_referer) {

   rewrite ^/ ;

    # return 403;

   }

}

5.Nginx expires

# Add expires header for static content

location ~* \.(js|css|jpg|jpeg|gif|png|swf)$ {

if (-f $request_filename) {

   root /data/www/wwwroot/bbs;

   expires    1d;

   break;

}

}

6.根据判断某个目录

# serve static files

location ~ ^/(images|javascript|js|css|flash|media|static)/   {

root /data/www/wwwroot/down;

       expires 30d;

   }

7.Nginx 访问控制

#cd /usr/local/nginx/conf

#mkdir htpasswd

/usr/local/apache2/bin/htpasswd -c /usr/local/nginx/conf/htpasswd/tongji linuxtone #添加用户名为linuxtone

New password: (此处输入你的密码)

Re-type new password: (再次输入你的密码)

Adding password for user

http://count.linuxtone.org/tongji/data/index.html(目录存在/data/www/wwwroot/tongji/data/目录下)

将下段配置放到虚拟主机目录,当访问http://count.linuxtone/tongji/即提示要密验证:

location ~ ^/(tongji)/   {

            root /data/www/wwwroot/count;

                     auth_basic              "LT-COUNT-TongJi";

                     auth_basic_user_file   /usr/local/nginx/conf/htpasswd/tongji;

            }

8.Nginx下禁止访问*.txt文件,配置方法如下.代码:
location ~* \.(txt|doc)$ {

if (-f $request_filename) {

root /data/www/wwwroot/linuxtone/test;

break;

}

}

方法2:

location ~* \.(txt|doc)${

       root /data/www/wwwroot/linuxtone/test;

       deny all;

}

禁止访问某个目录
location ~ ^/(WEB-INF)/ {

         deny all;

}

9.使用ngx_http_access_module限制ip访问

location / {

deny 192.168.1.1;

allow 192.168.1.0/24;

allow 10.1.1.0/16;

deny all;

}

更多内容参考http://hi.baidu.com/hontlong/blo ... c3c0eb8a1399f6.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP