快速搭建nginx,并做身份证校验

  1. 安装nginx
    yum -y install nginx

  2. 修改nginx配置
    vi /etc/nginx/nginx.conf

worker_processes  1;
events {
   worker_connections  1024;
}
http {
   include       mime.types;
default_type  application/octet-stream;
#添加upstream模块
   upstream kibana_web {
   server 10.0.200.105:5601 weight=1 max_fails=2 fail_timeout=30s;
   }
   sendfile        on;
   keepalive_timeout  65;
   server {
       listen       5601;
       server_name  localhost;
       location / {
           auth_basic "The Kibana Monitor Center";
           auth_basic_user_file /usr/share/nginx/html/.htpasswd;
           root   html;
           index  index.html index.htm;
           proxy_set_header Host $host;
           proxy_pass http://kibana_web;
   }
       error_page   500 502 503 504  /50x.html;
       location = /50x.html {
           root   html;
       }
   }
}

其中

auth_basic "The Kibana Monitor Center";
auth_basic_user_file /usr/share/nginx/html/.htpasswd; 配置权限
proxy_pass 做转发用

3.添加用户

htpasswd -c /usr/share/nginx/html/.htpasswd xxx

如果没有htpasswd命令则

yum install httpd-tools 

4.如果需要多个用户则每个用户配置一个端口即可

你可能感兴趣的:(快速搭建nginx,并做身份证校验)