yum install httpd -y         安裝apache軟件包

systemctl start httpd       啟動apache服務

systemctl stop firewalld
systemctl enable httpd
systemctl disable firewalld

netstat  -antlpe | grep httpd                ##查看監聽端口

#####apache的基本配置#######
1.apache的默認發布文件
index.html

2.apache的配置文件
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf

3.apache的默認發布目錄
/var/www/html

默認發布文件

4.apache的默認端口
80

######修改apache的基本配置########
1.修改默認發布文件

vim /etc/httpd/conf/httpd.conf

164    DirectoryIndex westos.html  index.html       ##
默認主頁名稱

systemctl restart httpd

2.修改默認發布目錄CDN0pxPFU346.png/>
    ###當selinux是disable狀態時
vim /etc/httpd/conf/httpd.conf

120 DocumentRoot "/westos/www/html"         ##網頁文件的存放目錄
121 <Directory "/westos/www/html">        ##語句塊自定義目錄權限
122      Require all granted
123 </Directory>

systemctl restart httpd

       

##當selinux是Enforcing狀態時

semanage fcontext -a -t httpd_sys_content_t '/westos(/.*)?'        ##配置安全上下文
restorecon -RvvF /westos
測試:172.25.254.162

3.apache的訪問控制
vim /etc/httpd/conf/httpd.conf

<Directory "/var/www/html/admin">   ##允許所有人訪問admin目錄但拒絕62主機
    Order Allow,Deny
    Allow from All
    Deny from 172.25.254.62
</Directory>

<Directory "/var/www/html/admin">   ##只允許62主機訪問admin目錄
    Order Deny,Allow      
    Allow from 172.25.254.62
    Deny from All
</Directory>

systemctl restart httpd

測試:172.25.254.162/admin/

#####設定用戶的訪問########

#####用兩個賬戶創建Apache密碼文件

htpasswd -cm /etc/httpd/accessuser admin   ##建立用戶認證文件并建立用戶admin設置密碼123
htpasswd -m /etc/httpd/accessuser cui      ##建立認證用戶cui,密碼123

vim /etc/httpd/conf/httpd.conf               ##配置基于用戶的身份驗證

<Directory "/var/www/html/admin">
        AuthUserFile/etc/httpd/accessuser    ##用戶認證文件
        AuthName "Please input yourname and password !!"  ##用戶認證提示信息
        AuthType basic    ##認證類型
        Require valid-user    ##認證用戶,認證文件中所有的用戶都可以通過
      或  [Require user admin]  ##只允許認證文件中的admin用戶訪問,二寫一
</Directory>

systemctl restart httpd           ##重啟apache服務,并使用Web瀏覽器測試訪問,在彈出的對話框中輸入上述用戶名和密碼。

測試:172.25.254.162/admin/

4.apache 語言支持
html語言支持
php語言支持
yum install php -y        ##安裝php服務

vim /var/www/html/index.php       ##寫php測試

<?php
        phpinfo()
?>

systemctl restart httpd
測試:172.25.254.162

**cgi語言支持
mkdir /var/www/html/cgi
vim /var/www/html/cgi/index.cgi   ##默認發布文件主頁內容

#!/usr/bin/perl
print "Content-type: text/html\\\\n\\\\n";
print `date`;

vim /etc/httpd/conf/httpd.conf

<Directory "/var/www/html/cgi">        ##網頁文件目錄
        Options  ExecCGI
        AddHandler cgi-script .cgi
</Directory>
 DirectoryIndex index.cgiindex.html    ##默認訪問主頁名稱

systemctl restart httpd
chmod x index.cgi        ##給文件添加執行權限
測試:
172.25.254.136/cgi/

#####Apache的虛擬主機#####

1.定義
可以讓我們的一臺apache服務器在被訪問不同域名的時候顯示不同的主頁

虛擬主機允許您從一個httpd服務器同時為多個網站提供服務。在本節中,我們將了解基于名稱的虛擬主機其中多個主機名都指向同一個IP地址,但是Web服務器根據用于到達站點的主機名提供具有不同內容的不同網站。

2.建立測試頁

##########建立網頁發布目錄#######

mkdir /var/www/virtual/money.westos.com/html -p
mkdir /var/www/virtual/news.westos.com/html -p
echo "<h2>news.westos.coms's page</h2>">/var/www/virtual/news.westos.com/html/index.html
echo "<h2>money.westos.coms's page</h2>">/var/www/virtual/money.westos.com/html/index.html

3.配置##創建虛擬主機配置文件

vim /etc/httpd/conf.d/default.conf      ##未指定域名的訪問都訪問default     

###這是定義虛擬主機的塊

<Virtualhost   _default_:80>                 ##虛擬主機開啟的端口             
    DocumentRoot"/var/www/html"        ##虛擬主機默認發布目錄    
    CustomLog "logs/default.log"combined    ##虛擬主機日志
</Virtualhost>

vim /etc/httpd/conf.d/news.conf      ##指定域名news.westos.com的訪問到指定的默認發布目錄中

<Virtualhost  *:80>
    ServerName"news.westos.com"            ##指定服務器名稱
    DocumentRoot"/var/www/virtual/news.westos.com/html"      ##默認發布目錄的訪問授權
      CustomLog "logs/news.log"combined          ##虛擬主機日志
</Virtualhost>
<Directory "/var/www/virtual/news.westos.com/html">      ##語句塊自定義目錄權限
        Require all granted
</Directory>

vim /etc/httpd/conf.d/money.conf

<Virtualhost  *:80>
    ServerName"money.westos.com"                     
    DocumentRoot"/var/www/virtual/money.westos.com/html"
    CustomLog "logs/money.log"combined
</Virtualhost>
<Directory "/var/www/virtual/money.westos.com/html">
    Require all granted
</Directory>

systemctl start httpd        ##啟動apache服務

    
4.測試
在瀏覽器所在主機中
vim /etc/hosts
172.25.254.136  www.westos.comnews.westos.com money.westos.com

####https#####
1.https定義
通過ssl加密

2.配置
yum install mod_ssl -y            ##安裝證書及其私鑰

yum install crypto-utils -y        ##安裝crypto-utils軟件包
genkey www.westos.com        ##調用genkey,同時為生成的文件指定唯一名稱

##記錄生成的證書(www.westos.com.crt)和關聯的私鑰(www.westos.com.key)的位置:

##繼續使用對話框,并選擇合適的密鑰大小:

##在生成隨機數時比較慢,敲鍵盤和移動鼠標可以加速

##拒絕向認證機構(CA)發送證書請求(CSR)。

##拒絕加密私鑰

##為服務器提供合適的身份

##得到/etc/pki/tls/certs/www.westos.com.crt
/etc/pki/tls/private/www.westos.com.key
##編輯/etc/httpd/conf.d/ssl.conf, 將SSLCertificateFile和SSLCertificateKeyFile指令設置為分別指向X.509證書和密鑰文件。

vim /etc/httpd/conf.d/login.conf

<Virtualhost  *:443>            ##訪問443端口        
    ServerName"login.westos.com"        ##指定服務器名稱                                                        
    DocumentRoot"/var/www/virtual/login.westos.com/html"         ##網頁文件的存放目錄              
    CustomLog"logs/login.log" combined        ##日志        
    ssLEngine on     ##開啟https功能        
    SSLCertificateFile  /etc/pki/tls/certs/www.westos.com.crt  ## 證書        
    SSLCertificateKeyFile/etc/pki/tls/private/www.westos.com.key ##密鑰
</Virtualhost>
<Directory "/var/www/virtual/login.westos.com/html">       
    Require all granted
</Directory>
<Virtualhost  *:80>    ##網頁重寫把所有80端口的請求全部重定向由https來處理
       ServerName"login.westos.com"        
       REwriteEngine on        
       RewriteRule^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</Virtualhost>
#^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
解析
#^(/.*)$             客戶主機在地址欄中寫入的所有字符,不好看換行符
#https://       定向成功的訪問協議
#%{HTTP_HOST}   客戶請求主機
#$1             $1的值就表示^(/.*)$的值 
#[redirect=301]  臨時重定向  302永久重定向

mkdir /var/www/virtual/login.westos.com/html -p
vim /var/www/virtual/login.westos.com/html/index.html

<h2>haha www.westos.com</h2>

systemctl restart httpd

測試:
在客戶主機中添加解析
vim /etc/hosts
172.25.254.136 login.westos.com

訪問http://login.westos.com會自動跳轉到
https://login.westos.com實現網頁數據加密傳輸

更多關于云服務器域名注冊,虛擬主機的問題,請訪問三五互聯官網:m.shinetop.cn

贊(0)
聲明:本網站發布的內容(圖片、視頻和文字)以原創、轉載和分享網絡內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。郵箱:3140448839@qq.com。本站原創內容未經允許不得轉載,或轉載時需注明出處:三五互聯知識庫 » 3-unit9 apache

登錄

找回密碼

注冊

主站蜘蛛池模板: 国产精品日韩精品日韩| 午夜亚洲国产理论片二级港台二级| 国产视频精品一区 日本| 亚洲综合色丁香婷婷六月图片| 四虎永久在线精品8848a| 免费人成网站视频在线观看 | 又黄又刺激又黄又舒服| 精品一日韩美女性夜视频| 中文字幕日韩精品无码内射| 久久精品蜜芽亚洲国产AV| 在线看片免费不卡人成视频| 熟女精品视频一区二区三区| 精品超清无码视频在线观看| h无码精品3d动漫在线观看| 国产亚洲精品一区二区不卡| 国内精品伊人久久久久AV一坑| 日本一区二区三区在线 |观看 | av色综合久久天堂av色综合在| 国产在线精彩自拍视频| 女主播扒开屁股给粉丝看尿口| 五月丁香六月狠狠爱综合| 东京一本一道一二三区| 四虎国产精品永久在线| 粉嫩一区二区三区粉嫩视频| 狠狠色丁香婷婷久久综合五月| 97国产成人无码精品久久久| 国产无遮挡猛进猛出免费软件| 亚洲av免费看一区二区| 亚洲人成网站77777在线观看 | 精品91在线| 热久久美女精品天天吊色| 色综合五月伊人六月丁香| 国产真实乱人偷精品人妻| 国产美女午夜福利视频| 中文字幕国产精品日韩| 亚洲国产精品一区二区第一页| 免费十八禁一区二区三区| 欧美日产国产精品| 欧美日韩中文字幕久久伊人| 久久国产免费观看精品3| 国产偷人妻精品一区二区在线|