Apache服务虚拟机的安装配置(企业级)

–>

在企业里面不同的域名下都是真实的服务器,但我们做实验,在一台主机里配置不同域名的服务器

[[email protected] html]# cd /var/www/
[[email protected] www]# ls
cgi-bin  html
[[email protected] www]# mkdir westos.com/news/html -p
[[email protected] www]# mkdir westos.com/music/html -p
[[email protected] www]# ls
cgi-bin  html  westos.com
[[email protected] www]# vim westos.com/news/html/index.html
<h1>news's page</h1>
[[email protected] www]# vim westos.com/music/html/index.html
<h1>music's page</h1>
[[email protected] www]# cd /etc/httpd/conf.d
[[email protected] conf.d]# ls
autoindex.conf  manual.conf  README  userdir.conf  welcome.conf
[[email protected] conf.d]# vim a_default.conf
<VirtualHost _default_:80>
        DocumentRoot /var/www/html
        Customlog logs/default.log combined
</VirtualHost>

[[email protected] conf.d]# systemctl restart httpd.service 
[[email protected] conf.d]# vim music.conf
login.log<VirtualHost *:80>
        ServerName music.westos.com
        DocumentRoot /var/www/westos.com/music/html
        Customlog logs/music.log combined
</VirtualHost>
<Directory "/var/www/westos.com/music/html">
        Require all granted
</Directory>
~                         

[[email protected] conf.d]# systemctl restart httpd.service 
[[email protected] conf.d]# vim news.conf
<VirtualHost *:80>
        ServerName news.westos.com
        DocumentRoot /var/www/westos.com/news/html
        Customlog logs/news.log combined
</VirtualHost>
<Directory "/var/www/westos.com/news/html">
        Require all granted
</Directory>
~                                
[[email protected] conf.d]# cp music.conf news.conf 
cp: overwrite ‘news.conf’? y
[[email protected] conf.d]# vim news.conf
[[email protected] conf.d]# systemctl restart httpd.service 
在真机里面添加本地解析
[[email protected] ~]# vim /etc/hosts
172.25.254.249 www.westos.com news.westos.com music.westos.com
####apache访问控制####
[[email protected] conf.d]# vim a_default.conf 
<VirtualHost _default_:80>
        DocumentRoot /var/www/html
        Customlog logs/default.log combined
</VirtualHost>
权限控制访问
<Directory "/var/www/html">
        Order Allow,Deny  后者覆盖前者
        Allow from all
        Deny from 172.25.254.49
</Directory>

1.在/var/www/下创建两个不同发布目录,写上内容,

2.在/etc/httpd/conf.d/下写上本机和刚才创建的两个发布目录的配置文件,都以.conf结尾
本地默认发布目录的配置文件

music发布目录的配置文件

发布端口80
Customlog 为日志文件 后面的为所在位置
Directory为访问的权限设定,此处为所有人

news发布目录的配置文件

重新启动服务

3.在真机里面添加本地域名解析,ip为刚才apache-server服务器的ip

4.即可访问刚才服务器配置的发布文件

5.刚才发布目录都是所有人可访问,我们也可以给特定的权限

http用户密码访问的设定

[[email protected] conf.d]# htpasswd -cm http_userlist admin 添加用户和访问密码
New password: 
Re-type new password: 
Adding password for user admin
[[email protected] conf.d]# htpasswd -m http_userlist admin1  再次添加-m不要-c
New password: 
Re-type new password: 
Adding password for user admin1
[[email protected] conf.d]# cat http_userlist   查看添加的用户和密码
admin:$apr1$aIsHJGj8$ImxO4o4o47unrkEGK8Jck1
admin1:$apr1$OH3kajLy$fWBW/keDwuV9lJ.O/JBqR/

<Directory "/var/www/html">
        AuthUserFile /etc/httpd/conf.d/http_userlist
        AuthName "Please input username and password!!!"
        AuthType basic
#Require user admin
        Require valid-user
</Directory>

1.建立用户和密码,注c再添加用户密码时不要加c了,否则前一个用户密码会被覆盖
htpasswd -cm http_userlist yonghu 添加用户
cat http_userlist 可以查看创建的用户和密码

2.编辑发布目录的配置文件,此处我们编辑默认发布目录的配置文件
AuthUserFile /etc/httpd/conf.d/http_userlist 指向用户密码所在文件
AuthName “Please input username and password!!!” 会在访问时弹出
AuthType basic 加密类型,基本加密
#Require user admin 允许admin用户
Require valid-user 允许所有用户登录

3.重新启动服务

4.在网页上进行访问,输入用户名和密码

本文来源 互联网收集,文章内容系作者个人观点,不代表 本站 对观点赞同或支持。如需转载,请注明文章来源,如您发现有涉嫌抄袭侵权的内容,请联系本站核实处理。

© 版权声明

相关文章