nginx配置下载目录
http {
server {
#autoindex on;
fancyindex on; #开启下载目录显示
fancyindex_exact_size off; #以可读性更好的方式显示
fancyindex_footer "footer.html"; #加载footer.html内容为页脚
location / {
index index
}
}
}
nginx压缩文件
http {
gzip on; #开启gzip压缩
gzip_http_version 1.0; #指定使用版本
gzip_disable "MSIE[1-6]"; #Ie6以下禁用
gzip_types image/jpeg image/jpg; #指定需要压缩的文件类型
}
nginx缓存文件
http {
server {
location / {
index index
}
location ~ \.(js|css)$ {
#缓存时间
expires 1h;
}
}
}
nignx配置家目录与域名
http {
server {
server_name www.shop.com #域名
root html/shop #家目录
}
}
nginx配置网站通过授权账号与密码访问,安装httpd-tools服务
http {
server {
auth_basic "please input password"; #提示信息
auth_basic_user_file /usr/local/nginx/conf/passwd.db; #密码文件,用【htpasswd -c 地址 用户名】生成
}
}
nginx配置限制网段或ip
http {
server {
allow 192.168.159.1; #允许ip
deny all; #禁用网段
}
}
nginx输出内容
http {
root /html/testhome
server {
location / {
default_type text/plain;
echo $document_root; #输出家目录的地址
}
}
}
nginx日志相关内容
http {
#定义日志模板
log_format shoplog '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
#应用日志模板
server {
access_log logs/shop.log shoplog;
}
}
nginx rewrite应用
http {
server_name www.shop.com;
#域名切换
rewrite / http://www.baidu.com permanent;
}
nginx 隐藏版本号
http {
#隐藏版本号
server_tokens off;
}
防盗链接
http {
server_name www.shop.com;
server {
location / {
valid_refers www.shop.com;
if ($invalid_refer) {
return 404; #返回状态码
}
}
}
}