Nginx 的请求限制
- 连接频率限制 - limit_conn_module
- 请求频率限制 - limit_req_module
Nginx 的访问控制
- 基于 IP 的访问控制 - http_access_module
- 基于用户的信任登录 - http_auth_basic_module
http_access_module
server {
listen 80;
server_name localhost;
location ~ ^/admin.html {
root /app/nginx/html/access;
# 禁止 172.27.254.48 IP访问
deny 172.27.254.48;
allow all;
index admin.html admin.htm;
}
location ~ ^/admin.html {
root /app/nginx/html/access;
# 只允许 172.27.254.48 IP访问
allow 172.27.254.48;
deny all;
index admin.html admin.htm;
}
}
http_auth_basic_module
安装 httpd-tools
yum install httpd-tools -y
生成密钥
htpasswd -c ./auth_conf admin
image.png
配置 conf
server {
listen 80;
server_name localhost;
location / {
root /app/nginx/html/proxy;
index proxy.html index.htm;
}
location /access {
alias /app/nginx/html/access;
# 配置参数
auth_basic "Auth access test!input your passward!";
auth_basic_user_file /app/nginx/auth_conf;
index admin.html;
}
}
reload 之后页面访问
image.png
image.png