基于用户的访问
安装包
[root@localhost ~]# yum provides *bin/htpasswd
已加载插件:fastestmirror
Repository 'base': Error parsing config: Error parsing "baseurl = 'local'": URL must be http, ftp, file or https not ""
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
httpd-tools-2.4.6-93.el7.centos.x86_64 : Tools for use with the Apache HTTP Server
源 :base
匹配来源:
文件名 :/usr/bin/htpasswd
[root@localhost ~]# yum -y install httpd-tools
[root@localhost ~]# which htpasswd
/usr/bin/htpasswd
[root@localhost ~]# htpasswd -c -m /usr/local/nginx/conf/.passwd admin
New password:
Re-type new password:
Adding password for user admin
[root@localhost ~]# ls /usr/local/nginx/conf/ -a
. fastcgi_params.default nginx.conf uwsgi_params
.. koi-utf nginx.conf.default uwsgi_params.default
fastcgi.conf koi-win .passwd win-utf
fastcgi.conf.default mime.types scgi_params
fastcgi_params mime.types.default scgi_params.default
[root@localhost ~]# cat /usr/local/nginx/conf/.passwd 即加密后的密码
admin:$apr1$Ky/Dnmpe$DVuYt3vuP/BNdUt3/OP8R/
配置页面
[root@localhost ~]# cd /usr/local/nginx/html/
[root@localhost html]# ls
50x.html index.html zabbix
[root@localhost html]# mkdir abc
[root@localhost html]# echo 'abc test page' > abc/index.html
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
[root@localhost ~]# nginx -s reload
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /abc { //配置abc页面
root html;
index index.html;
}
配置密码
[root@localhost ~]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@localhost ~]# nginx -s reload
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
location /abc {
auth_basic "jjyy";
auth_basic_user_file /usr/local/nginx/conf/.passwd; 添加密码位置
root html;
index index.html;
}
页面测试
配置HTTPS
下载证书需要的包
[root@localhost ~]# yum -y install mod_ssl
[root@localhost ~]# vim /etc/httpd/conf.modules.d/00-base.conf
添加以下内容
LoadModule ssl_module modules/mod_ssl.so
[root@localhost ~]# openssl genrsa -out server.key 2048
Generating RSA private key, 2048 bit long modulus
.............................................+++
.................................+++
e is 65537 (0x10001)
[root@localhost ~]# openssl req -new -key server.key -out server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there