nginx高级配置

重定向

   if ($host != 'www.discuz.com'){
                rewrite ^/(.*)$  http://www.discuz.com/$1  permanent;
        }

1.用户认证

location ~ .*admin\.php {
                    auth_basic              "Auth";
                    auth_basic_user_file   /usr/local/nginx/conf/htpasswd;
                    include fastcgi_params;
                    fastcgi_pass unix:/tmp/www.sock;
                    fastcgi_index index.php;
                    fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;

            }

说明:后面include开始是用来解析php的,

这部分是解析php的配置

 location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/tmp/www.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /data/www$fastcgi_script_name;
    }

不记录指定日志&&防盗链

location ~ .*\.(gif|png|jpg|css|js|mp4|flv|rar|zip|swf|pdf|gz|bz2|doc)$ {
    access_log off;
    expires 1h;
    valid_referers none blocked server_names *.discuz.com;
    if ( $invalid_referer ) {
            return 403;
            #或者rewrite到指定页面;
            }
    }

日志的切割是由脚本来完成的

你可能感兴趣的:(linux)