1. 程式人生 > >Apache服務虛擬機器的安裝配置(企業級)

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.在網頁上進行訪問,輸入使用者名稱和密碼
在這裡插入圖片描述
在這裡插入圖片描述