Linux系统基础知识(13)Web网站服务管理

人生难得几回搏,此时不搏待何时。这篇文章主要讲述Linux系统基础知识(13)Web网站服务管理相关的知识,希望能为你提供帮助。
1.客户端地址限制通过Require配置项实现也止限制功能

  • Require all granted:表示所有主机允许访问
  • Require all denied:表示拒绝所有主机访问
  • Require local:表示仅允许本地主机访问
  • Require [not] host < 主机名或域名列表> :
  • Require [not] ip < IP地址或网段列表>
演示和操作
环境:编译安装Apache??https://blog.51cto.com/u_15630500/5296651??
  • 修改配置文件
[root@localhost ~]#vim /usr/local/httpd/conf/httpd.conf//配置文件路径
#254行前添加
< RequireALL>
Require all granted
Require not ip 192.168.19.102
< /RequireALL>

[root@localhost conf]# systemctl restart httpd

  • 客户端配置访问:
192.168.19.102
[root@localhost ~]# yum -y install elinks
[root@localhost ~]# elinks 192.168.19.100


192.168.19.103
[root@localhost ~]# yum -y install elinks
[root@localhost ~]# elinks 192.168.19.100




2.用户权限管理
[root@localhost httpd]# ll /usr/local/httpd/bin


使用htppasswd创建用户
[root@localhost httpd]# htpasswd -c /usr/local/httpd/conf/.awspwd webadmin
New password:
Re-type new password:
Adding password for user webadmin
[root@localhost httpd]# htpasswd/usr/local/httpd/conf/.awspwd test
New password:
Re-type new password:
Adding password for user test

[root@localhost httpd]# vim /usr/local/httpd/conf/httpd.conf
#254行前添加
AuthName "DocumentRoot"
AuthType Basic
AuthUserFile /user/local/httpd/conf/.awspwd
Require webadmin

  • AuthName:定义受保护的领域名称,该内容将在浏览器弹出的认证对话框中显示
  • AuthType:认证类型,Basic表示基本认证
  • AuthUserFile:这种用户账户,密码的路径
  • Require valied-user:用户访问
192.168.19.103
[root@localhost ~]#elinks 192.168.19.100




3.虚拟web主机环境准备:
[root@localhost httpd]# mkdir -p /var/www/html/blab1.com
[root@localhost httpd]# mkdir -p /var/www/html/blab2.com
[root@localhost httpd]# echo "< h1> www.blab1/com< /h1> " > /var/www/html/blab1.com/index.html
[root@localhost httpd]# echo "< h1> www.blab2/com< /h1> " > /var/www/html/blab2.com/index.html

192.168.19.103
[root@slave1 ~]# echo "192.168.19.100 www.blab1.com" > > /etc/hosts
[root@slave1 ~]# echo "192.168.19.100 www.blab2.com" > > /etc/hosts



修改配置文件:
[root@localhost httpd]# vim/usr/local/httpd/conf/extra/httpd-vhosts.conf
< VirtualHost *:80>
ServerAdmin www.blab1.com
DocumentRoot "/var/www/html/blab1.com"
ServerName www.blab1.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/www.blab1.com-error_log"
CustomLog "logs/www.blab1.com-access_log" common
< Directory "/var/www/html">
Require all granted
< /Directory>
< /VirtualHost>

< VirtualHost *:8080>
ServerAdmin www.blab2.com
DocumentRoot "/var/www/html/blab2.com"
ServerName www.blab2.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/www.blab2.com-error_log"
CustomLog "logs/www.blab2.com-access_log" common
< Directory "/var/www/html">
Require all granted
< /Directory>
< /VirtualHost>

启用配置文件:
[root@localhost httpd]# vim /usr/local/httpd/conf/httpd.conf
Listen 8080//53行附近添加

Include conf/extra/httpd-vhosts.conf//486行附近开启

[root@localhost httpd]# systemctl restarthttpd.service

192.168.19.103测试
[root@localhost ~]# elinks www.blab1.com


[root@localhost ~]# elinks www.blab2.com


[root@localhost ~]#elink 192.168.19.100:8080




【Linux系统基础知识(13)Web网站服务管理】


    推荐阅读