默认网站配置(未更改前)
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
#支持目录浏览
autoindex on;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
一、配置访问控制
location /a {
autoindex on;
allow 192.168.12.0/24;
deny all;
#基于客户端IP做过滤,符合条件的允许访问,不符合的返回404;
if ( $remote_addr !~ "192.168.12" ) {
return 404;
}
}
二、配置登录验证
location /c {
auth_basic "登陆验证";
auth_basic_user_file /etc/nginx/htpasswd;
}
三、配置网站防盗链
location /images/ {
alias /data/images/;
valid_referers none blocked *.cnblogs.com; #信任源地址
if ($invalid_referer) { #如果是非信任地址就重定向到百度或返回403
rewrite ^/ https://www.baidu.com;
#return 403;
}
}
标签:选项,index,配置,192.168,Nginx,html,location,images
From: https://www.cnblogs.com/tjane/p/16861610.html