Apache服務html
1.yum install httpd -ylinux
2.yum install httpd-manual -y#安裝手冊web
3.systemctl start httpdvim
一.修改默認的發佈目錄瀏覽器
通常來講http服務的默認發佈目錄在/var/www/html頁面中。首先讀取首頁index.htmldom
如何修改:ide
1. vim /etc/httpd/conf/httpd.conf 測試
119 # DocumentRoot "/var/www/html"#將原來的默認發佈目錄註釋。方便恢復ui
120 DocumentRoot "/www/lyitx"#指定新的默認發佈目錄spa
121 <Directory "/www/lyitx">
122 Require all granted#容許全部人訪問
123 </Directory>
2.建立目錄
mkdir -p /www/lyitx
cd /www/lyitx
vim index.html
內容不限制
<html>
<body>
<h1>這裏是lyitx目錄</h1>
</body>
</html>
重啓服務
Systemctl restart httpd
測試:
在火狐瀏覽器中輸入:
172.25.254.66/index.html
實驗成功
2.設置ip訪問權限
A.訪問黑名單-禁止某個ip訪問
vim /etc/httpd/conf/httpd.conf
在以前修改的文件上修改
121 <Directory "/www/lyitx">
122 Require all granted
123 Order Allow,Deny#系統默認先讀前面的Allow,再讀Deny
124 Allow from All#容許全部人訪問
125 Deny from 172.25.254.50#除了50主機
126 </Directory>
<Directory "/www/lyitx">
Require all granted
Order Allow,Deny
Allow from All
Deny from 172.25.254.0/24
</Directory>
如此設置:容許除了172.25.254.x網段的全部ip訪問
<Directory "/www/lyitx">
Require all granted
Order Deny,Allow#先讀去前面的deny-拒絕全部人,再容許50主機
Deny from All
Allow from 172.25.254.50
</Directory>
只有50主機能訪問:
三.密碼驗證登錄
cd /etc/httpd/
htpasswd -cm htpasswdfile admin #首次創建登錄用戶用-cm參數
htpasswd -m htpasswdfile lyitx#再次創建時則只用-m參數,不然會把以前創建的用戶清空
[root@web httpd]# ls
conf conf.d conf.modules.d htpasswdfile logs modules run
[root@web httpd]# cat htpasswdfile
admin:$apr1$lWEEQdgR$vkBPESs4VC15d0ZS1PViq1
lyitx:$apr1$cHaORGNS$ZRafBI0TRqEoJkEAnykZ/.
編輯配置文件:
vim /etc/httpd/conf/httpd.conf
121 <Directory "/www/lyitx">
122 AllowOverride All
123 Authuserfile /etc/httpd/htpasswdfile
124 Authname "please input username & password"
125 Authtype basic
126 Require user admin#只有admin用戶才能夠登錄
127 </Directory>
systemctl restart httpd.service
#只有擁有賬號密碼的用戶纔可登錄
vim /etc/httpd/conf/httpd.conf
# Require all granted
AllowOverride All
Authuserfile /etc/httpd/htpasswdfile
Authname "please input username & password"
Authtype basic
Require valid-user##前面麼有user
再重啓服務
四.虛擬主機,域名登錄
作實驗前先還原以前的操做,
Vim /etc/httpd/conf/httpd.conf
119 DocumentRoot "/var/www/html"
120 #DocumentRoot "/www/lyitx"
121 #
122 # Relax access to content within /var/www.
123 #
124 <Directory "/var/www">
125 AllowOverride None
126 # Allow open access:
127 Require all granted
128 </Directory>
重啓服務
1.mkdir /var/www/virtual/news.lyitx.com/html -p
2.mkdir /var/www/virtual/music.lyitx.com/html -p
3.cd /var/www/virtual/muisc.lyitx.com/html/
4.vim index.html
<html>
<body>
<h1>這裏是music</h1>
</body>
</html>
5.cd /var/www/virtual/news.lyitx.com/html/
6.vim index.html
<html>
<body>
<h1>這裏是news</h1>
</body>
</html>
7.cd /etc/httpd/conf.d/
8.vim default.conf
<Virtualhost _default_:80>
Documentroot /var/www/html
Customlog "logs/default.log" combined
</Virtualhost>
<Directory "/var/www/html">
Require all granted
</Directory>
9.vim news.conf
<Virtualhost *:80>
Servername news.lyitx.com
Documentroot /var/www/virtual/news.lyitx.com/html
Customlog "logs/default.log" combined
</Virtualhost>
<Directory "/var/www/virtual/news.westos.com/html">
Require all granted
</Directory>
10.vim music.conf
<Virtualhost *:80>
Servername music.lyitx.com
Documentroot /var/www/virtual/music.lyitx.com/html
Customlog "logs/default.log" combined
</Virtualhost>
<Directory "/var/www/virtual/music.westos.com/html">
Require all granted
</Directory>
重啓服務
11.訪問頁面的主機上加入解析
Vim /etc/hosts
172.25.254.66 www.lyitx.com lyitx.com news.lyitx.com music.lyitx.com#發佈共享的主機ip
測試:
######https###########
1.yum install mod_ssl -y
2. yum install crypto-utils -y
3.genkey www.lyitx.com
/usr/bin/keyutil -c makecert -g 1024 -s "CN=www.lyitx.com, OU=linux, O=westos, L=xi'an, ST=shannxi, C=CN" -v 1 -a -z /etc/pki/tls/.rand.9611 -o /etc/pki/tls/certs/www.lyitx.com.crt -k /etc/pki/tls/private/www.lyitx.com.key
cmdstr: makecert
cmd_CreateNewCert
command: makecert
keysize = 1024 bits
subject = CN=www.lyitx.com, OU=linux, O=lyitx, L=xi'an, ST=shannxi, C=CN
valid for 1 months
random seed from /etc/pki/tls/.rand.9611
output will be written to /etc/pki/tls/certs/www.lyitx.com.crt
output key written to /etc/pki/tls/private/www.lyitx.com.key
Generating key. This may take a few moments...
Made a key
Opened tmprequest for writing
/usr/bin/keyutil Copying the cert pointer
Created a certificate
Wrote 882 bytes of encoded data to /etc/pki/tls/private/www.lyitx.com.key
Wrote the key to:
/etc/pki/tls/private/www.lyitx.com.key
cd /etc/httpd/conf.d
vim ssl.conf
100 SSLCertificateFile /etc/pki/tls/certs/www.lyitx.com.crt
107 SSLCertificateKeyFile /etc/pki/tls/private/www.lyiyx.com.key
systemctl restart httpd.service
測試:
在瀏覽器中:
https://ip
查看證書