HTTP WEB服務 tcp80
使apache支持html
開啟httpd並查看有效內容
服務器操作
1.#yum insall httpd
2.#echo “test page” >/var/www/html/index.html
#systemctl restart httpd
客戶端測試
#yum install elinks
#links http://192.168.10.5
查看Apache當前工作模式
#httpd -V | grep “Server MPM”
修改Apache工作模式
#vim /etc/httpd/conf.modules.d/00-mpm.conf
-----------------------------------------------------------------------------------------------------------------------------
HTTP WEB服務 使apache支持perl腳本
服務器操作
1.#yum install perl perl-CGI -y[安裝perl支持程序]
2.#vim /etc/httpd/conf [修改httpd.conf配置]
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"[確認247行對cgi的支持]
3.Options FollowSymLinks ExecCGI [確認144行Apache允許執行CGI]
4.AddHandler cgi-script .cgi .pl[確認294行支持CGI后綴名的處理]
5.DirectoryIndex index.html index.cgi[確認164行支持index.cgi索引文件]
6. #vim /var/www/html/index.cgi[設置index.cgi腳本]
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<html>\n<body>\n";
print "<div style=\"width: 100%; fontsize:
40px; font-weight: bold; text-align:
center;\">\n";
print "CGI Test Page";
print "\n</div>\n";
print "</body>\n</html>\n";
7.#rm /var/www/html/index.html[刪除原先文件]
#chmod 705 /var/www/html/index.cgi[修改權限]
客戶端測試
#links http://192.168.10.5
-----------------------------------------------------------------------------------------------------------------------------
HTTP WEB服務 使apache支持php腳本
服務器操作
1.安裝php支持程序
#yum install php php-mbstring php-pear -y
2.確認php相關配置文件存在
#ls -l /etc/httpd/conf.d/php.conf
#ls -l /etc/httpd/conf.modules.d/10-php.conf
3.確認164行支持index.php索引文件
DirectoryIndex index.html index.php
4.創建index.php文件
#rm -i /var/www/html/index.cgi[將原先文件刪除]
#vim /var/www/html/index.php
<?php phpinfo(); ?>
5.重啟httpd服務
客戶端測試
#links http://192.168.10.5
-----------------------------------------------------------------------------------------------------------------------------
HTTP WEB服務 使apache支持ruby腳本
服務器操作
1.安裝ruby支持程序
#yum install ruby -y
2.#vim /etc/httpd/conf[修改httpd.conf配置]
確認247行對cgi的支持
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
確認144行Apache允許執行CGI
Options FollowSymLinks ExecCGI
確認294行支持CGI后綴名的處理
AddHandler cgi-script .cgi .rb
確認164行支持index.cgi索引文件
DirectoryIndex index.html index.rb
3.#vim /var/www/html/index.rb[設置index.rb腳本]
#vim /var/www/html/index.cgi
#!/usr/bin/ruby
print "Content-type: text/html\n\n"
print "<html>\n<body>\n"
print "<div style=\"width: 100%; fontsize:
40px; font-weight: bold; text-align:
center;\">\n"
print Time.now.strftime('%Y/%m/%d')
print "\n</div>\n"
print "</body>\n</html>\n"
4.增加index.cgi權限
#rm /var/www/html/index.php [刪除]
#chmod 705 /var/www/html/index.rb
5.重啟httpd服務
客戶端測試
#links http://192.168.10.5
-----------------------------------------------------------------------------------------------------------------------------
HTTP WEB服務 使apache支持python腳本
服務器操作
1.安裝程序
#yum install python mod_wsgi -y
2.確認wsgi模塊配置文件存在
#ls -l /etc/httpd/conf.modules.d/10-wsgi.conf
3.#vim /etc/httpd/conf[修改httpd.conf以支持python]
確認247行對cgi的支持
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
確認164行支持index.cgi索引文件
DirectoryIndex index.html index.php
確認144行Apache允許執行CGI
Options Indexes FollowSymLinks ExecCGI
確認294行支持CGI后綴名的處理
AddHandler cgi-script .cgi .py
4.#vim /var/www/html/index.py[設置index.py腳本]
import web
urls = (
'/(.*)', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self, name):
if not name:
name = 'World'
return 'Hello, ' + name + '!'
if __name__ == "__main__":
app.run()
app = web.application(urls, globals(), autoreload=False)
application = app.wsgifunc()
5.增加index.py權限
#rm /var/www/html/index.rb [刪除]
#chmod 705 /var/www/html/index.py
6.#systemctl restart httpd[重啟]
客戶端測試
#links http://192.168.10.5
-----------------------------------------------------------------------------------------------------------------------------
HTTP虛擬主機 FQDN
FQDN:需要DNS支持,並不同的FQDN配置為同一IP地址
服務器操作
1.#vim /etc/httpd/conf.d/yht.conf[配置基於不同FQDN的虛擬主機]
<Directory /var/www/fqdn/yht>
Require all granted
AllowOverride None
</Directory>
<VirtualHost *:80>
DocumentRoot /var/www/fqdn/yht
ServerName www.yht.bl
ServerAdmin webmaster@yht.bl
ErrorLog "logs/rh7s1_error_log"
CustomLog "logs/rh7s1_access_log"
common
</VirtualHost>
#vim /etc/httpd/conf.d/web.conf
<Directory /var/www/fqdn/www>
Require all granted
AllowOverride None
</Directory>
<VirtualHost *:80>
DocumentRoot /var/www/fqdn/www
ServerName web.edu.bl
ServerAdmin webmaster@ak.edu
ErrorLog "logs/web_error_log"
CustomLog "logs/web_access_log" common
</VirtualHost>
2.建立目錄
#mkdir -p /var/www/fqdn/yht
#mkdir -p /var/www/fqdn/www
3.建立index.html
#echo “hello yht ak47” > /var/www/fqdn/yht
#echo “hello yanghaitao ck007” > /var/www/fqdn/www
4.重啟apache
#systemctl restart httpd
客戶端測試
1.vim /etc/hosts[添加、修改host文件]
192.168.10.5 www.yht.bl
192.168.10.5 web.edu.bl
2.#links http://yht.edu.bl
3.# links http://web.edu.bl
-----------------------------------------------------------------------------------------------------------------------------
HTTP虛擬主機 IP
基基於不同IP的虛擬主機(需要本地主機有多個IP地址)
服務器操作
1.配置基於不同IP的虛擬主機
#vim /etc/httpd/conf.d/ip-1.conf[配置主機1]
<Directory /var/www/ip-1.conf>
Require all granted
AllowOverride None
</Directory>
<VirtualHost 192.168.10.101:80>
DocumentRoot /var/www/ip-1.conf
ServerName ck.edu.bl
ServerAdmin webmaster@edu.bl
ErrorLog "logs/rh7s1_error_log"
CustomLog "logs/rh7s1_access_log" common
</VirtualHost>
#vim /etc/httpd/conf.d/ip-2.conf[配置主機2]
#vim /etc/httpd/conf.d/ip-2.conf
<Directory /var/www/ip-2.conf>
Require all granted
AllowOverride None
</Directory>
<VirtualHost 192.168.10.100:80>
DocumentRoot /var/www/ip-2.conf
ServerName ak.edu.bl
ServerAdmin webmaster@edu.bl
ErrorLog "logs/web_error_log"
CustomLog "logs/web_access_log"common
</VirtualHost>
2.增加ip地址
#ip addr add 192.168.10.100/24 brd + dev eno16777736
#ip addr add 192.168.10.101/24 brd + dev eno16777736
3.建立目錄
#mkdir -p /var/www/ip-1.conf
#mkdir -p /var/www/ip-2.conf
4.建立index.html
#cd /var/www/ip-1.conf
#echo “hello ck007 snow” >index.thml
#cd /var/www/ip-2.conf
#echo “hello ak110 lisa” >index.thml
5.重啟apache
#systemctl restart httpd
客戶端測試
1.#vim /etc/hosts [添加、修改host文件]
192.168.10.100 ak.edu.bl
192.168.10.101 ck.edu.bl
2.#links http://192.168.10.100
3.#links http://192.168.10.101
____________________________________________________________________________________________________________________
HTTP port端口
基於同一IP不同端口的虛擬主機
服務器操作
1.#vim /etc/httpd/conf.d/port-1.conf[配置第一個端口]
<Directory /var/www/port-1.conf>
Require all granted
AllowOverride None
</Directory>
LIsten 1200→在本文件中指定端口后可以不用修改/etc/httpd/conf/httpd.conf系統文件
<VirtualHost 192.168.10.5:1200>
DocumentRoot /var/www/port-1.conf
ServerName fuck.edu.bl
ServerAdmin webmaster@niliu.edu
ErrorLog "logs/rh7s1_error_log"
CustomLog "logs/rh7s1_access_log" common
</VirtualHost>
2.#vim /etc/httpd/conf.d/port-2.conf[配置第二個端口]
<Directory /var/www/port-2.conf>
Require all granted
AllowOverride None
</Directory>
LIsten 1100 →在本文件中指定端口后可以不用修改/etc/httpd/conf/httpd.conf系統文件
<VirtualHost 192.168.10.5:1100>
DocumentRoot /var/www/port-2.conf
ServerName dog.edu.bl
ServerAdmin webmaster@niliu.edu
ErrorLog "logs/rh7s1_error_log"
CustomLog "logs/rh7s1_access_log" common
3.建立目錄
#mkdir -p /var/www/port-1.conf>
#mkdir -p /var/www/port-2.conf>
4.建立index.html
#echo “fuck 123” > /var/www/port-1.conf/index.html
#echo “dog 234” > /var/www/port-2.conf/index.html
5.修改apache配置文件 ←注:[上面文件沒有指定端口才需修改配置文件]
將42行Listen 80下面增加
Listen 888
Listen 8888
6.重啟apache
#systemctl restart httpd
7.查看啟動端口
#netstat -lant | grep 88
客戶端測試
1.#links http://192.168.10.5:1100
2.#links http://192.168.10.5:1200
-----------------------------------------------------------------------------------------------------------------------------
HTTP 基於不同FQDN不同端口的虛擬主機
需要DNS支持,並不同的FQDN配置為同一IP地址
服務器操作
1.配置基於不同FQDN的虛擬主機
#vim /etc/httpd/conf.d/123.conf
<Directory /var/www/123.conf>
Require all granted
AllowOverride None
</Directory>
Listen 1500 →在本文件中指定端口后可以不用修改/etc/httpd/conf/httpd.conf系統文件
<VirtualHost yn.yht.bl:1500>
DocumentRoot /var/www/123.conf
ServerName yn.yht.bl
ServerAdmin webmaster@yht.bl
ErrorLog "logs/rh7s1_error_log"
CustomLog "logs/rh7s1_access_log" common
</VirtualHost>
2.#vim /etc/httpd/conf.d/234.conf
<Directory /var/www/234.conf>
Require all granted
AllowOverride None
</Directory>
Listen 1510 →在本文件中指定端口后可以不用修改/etc/httpd/conf/httpd.conf系統文件
<VirtualHost beijing.to.bl:1510>
DocumentRoot /var/www/234.conf
ServerName beijing.to.bl
ServerAdmin webmaster@to.bl
ErrorLog "logs/rh7s1_error_log"
CustomLog "logs/rh7s1_access_log" common
</VirtualHost>
3.建立目錄
#mkdir -p /var/www/123.conf
#mkdir -p /var/www/234.conf
4.建立index.html
#echo "thers is 雲南 " >/var/www/123.conf/index.html
#echo “北京 234” > /var/www/234.conf/index.html
5.修改apache配置文件 ←注:[上面文件沒有指定端口才需修改配置文件]
將42行Listen 80下面增加
Listen 1500
Listen 1510
6.#vim /etc/hosts[添加host文件]
192.168.10.5 yn.yht.bl
192.168.10.5 beijing.to.bl
7.重啟apache
#systemctl restart httpd
8.查看啟動端口
#netstat -lant | grep 1500
客戶端測試
1.#links http://192.168.10.5:1500
2.#links http://192.168.10.5:1510
-----------------------------------------------------------------------------------------------------------------------------
HTTP 基於同一FQDN不同端口顯示不同內容
服務器操作
1.#vim ipandport.conf[配置基於不同端口的虛擬主機]
<Directory /var/www/ipandport/1>
Require all granted
AllowOverride None
</Directory>
Listen 2200
<VirtualHost *:2200>→此處*要在客戶端添加host文件,域名的話需在服務器和客戶端都添加host
DocumentRoot /var/www/ipandport.conf/1
ServerName ck.edu.bl
ServerAdmin webmaster@edu.bl
ErrorLog "logs/rh7s1_error_log"
CustomLog "logs/rh7s1_access_log" common
</VirtualHost>
<Directory /var/www/ipandport/2>
Require all granted
AllowOverride None
</Directory>
Listen 2201
<VirtualHost *:2201>此處*要在客戶端添加host文件,域名的話需在服務器和客戶端都添加host
DocumentRoot /var/www/ipandport.conf/2
ServerName ck.edu.bl
ServerAdmin webmaster@edu.bl
ErrorLog "logs/rh7s1_error_log"
CustomLog "logs/rh7s1_access_log" common
</VirtualHost>
2.#cd /var/www[創建文件目錄]
#mkdir -p ipandport.conf/1 ipandport.conf/2
#echo "111111111" >ipandport.conf/1/index.html
#echo "666666666" >ipandport.conf/2/index.html
3.重啟服務
#systemctl restart httpd
客戶端測試
1.#vim /etc/hosts[修改host文件]
192.168.10.5 ck.edu.bl
2.#links http://ck.edu.bl:2200
#links http://ck.edu.bl:2201
-----------------------------------------------------------------------------------------------------------------------------
HTTP 基於同一IP不同端口顯示不同內容
服務器操作
1.#vim portandip.conf[配置基於不同端口的虛擬主機]
<Directory /var/www/portandip/1>
Require all granted
AllowOverride None
</Directory>
Listen 1234
<VirtualHost 192.168.10.110:1234>
DocumentRoot /var/www/portandip/1
ServerName nanjing.edu.bl
ServerAdmin webmaster@edu.bl
ErrorLog "logs/rh7s1_error_log"
CustomLog "logs/rh7s1_access_log" common
</VirtualHost>
<Directory /var/www/portandip/2>
Require all granted
AllowOverride None
</Directory>
Listen 1235
<VirtualHost 192.168.10.110:1235>
DocumentRoot /var/www/portandip/2
ServerName nanjing.edu.bl
ServerAdmin webmaster@edu.bl
ErrorLog "logs/rh7s1_error_log"
CustomLog "logs/rh7s1_access_log" common
</VirtualHost>
2.#cd /var/www[創建文件目錄]
#mkdir -p portandip/1 portandip/2
#echo "8888 lisa" > portandip/1/index.html
#echo "9999 dachui" > portandip/2/index.html
3.重啟服務
#systemctl restart httpd
客戶端測試
#links http://192.168.10.110:1234
#links http://192.168.10.111:1235
-----------------------------------------------------------------------------------------------------------------------------
HTTP 配置https(http+ssl)
生成所需證書
1.生成秘鑰
#cd /etc/pki/tls/certs
#openssl genrsa -des3 -out web.key 1024
2.剝離key文件口令
#openssl rsa -in web.key -out web.key
#chmod 400 web.key
3.生成證書
#openssl req -new -x509 -days 3650 -key web.key -out web.crt
4.安裝apache ssl的支持軟件
#yum install mod_ssl -y
5.配置/etc/httpd/conf.d/ssl.conf 文件
取消59行注釋:
DocumentRoot “/var/www/ssl”
取消60行注釋,並改成HTTP的FQDN
ServerName ck.edu.bl:443
修改100行所指定的crt文件
SSLCertificateFIle
/etc/pki/tls/certs/web.crt
修改107行所指定的key文件
SSLCertificateKeyFIle /etc/pki/tls/certs/web.key
6.重啟apache服務
#systemctl restart httpd
客戶端測試
---------------------------------------------------------------------------------------------------------------------------
HTTP 配置ssl
配置轉發加密,以確保SSL安全
開啟92的SSL密碼生成方式,開啟93行加密
功能
1.配置HSTS(HTTP Strict TransportSecurity),防止web回話被劫持開關 說明
UserDir disabled 所有用戶均關閉此功能
UserDir enabled 所有用戶均啟用此功能
Userdir disabled thomas 對指定用戶關閉此功能
Userdir enabled snow 對指定用戶開啟此功能
UserDir disabled 所有用戶均關閉此功能
UserDir enabled snow 僅對 snow 開啟此功能
UserDIr disabled snow 僅對 snow 關閉此功能
UserDir enabled 對除 snow 賬戶外開啟此功能
1)在ssl.conf中添加
Header always set Strict-Transport-
Security "max-age=600"
//*max-age為用戶訪問后的存活時間,單位為
秒,如用戶於18:00對頁面請求,600秒后即過期
啟用用戶主頁功能
1.編輯userdir配置文件
#vim /etc/httpd/conf.d/userdir.conf
修改17行將其注釋
UserDir disabled
取消25行注釋
UserDir public_html
2.重啟httpd
#systemctl restart httpd
3.創建用戶public_html目錄、修改權限
#su – snow
$mkdir -v public_html
$echo “hello snow”>public_html/index.html
$chmod 711 /home/snow
$chmod 755 public_html
客戶端測試
#links http://ck.edu.bl/~snow
#links http://192.168.10.5/~snow