Apache

curl -I www.baidu.com    他的服務是用Apache源碼自己開發的  curl聯網才能用

搜狐用的nginx  騰訊用的是squidCDN加速)

 

Apache http協議共享文件

互聯網主流web引擎有 Apache nginx

 

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Apache的安裝

yum install -y httpd

systemctl start httpd

systemctl enable httpd

systemctl stop firewalld

systemctl disable firewalld

 

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修改成westos.html

index.html   westos.html裏面分別寫hello world  lala 做測試頁

systemctl restart httpd

 

2修改默認發佈目錄

##selinuxdisable狀態

vim /etc/httpd/conf/httpd.conf

120  DocumentRoot "/westos/www/test"  註釋掉上一行DocumentRoot"/var/www/html"

<Directory "/westos/www/test">

Require all granted

</Directory>

mkdir -p /westos/www/test

systemctl restart httpd  

這是默認目錄就改成了 /westos/www/test

 

apache的訪問控制

vim /etc/httpd/conf/httpd.conf

<Directory "/var/www/html/admin">    

order Allow,Deny

Allow from All

Deny from 172.25.254.250

</Directory>

允許所有人訪問admin目錄 但不允許172.25.254.250訪問

 

<Directory "/var/www/html/admin">    

    order DenyAllow    先讀deny語句

    Allow from 172.25.254.250

    Deny from All

</Directory>

只允許172.25.254.250訪問

 

設定用戶的訪問

htpasswd -m /etc/httpd/accessuser admin

vim /etc/httpd/conf/httpd.conf

<Directory "/var/www/html/admin">

AuthUserFile /etc/httpd/accessuser     用戶認證文件

AuthName "Please input your name and password!!"  用戶認證提示信息

AuthType basic    認證類型

Require valid-user 認證用戶,認證文件中所用用戶都可以訪問

[Require user admin] 只允許認證文件中admin用戶可以訪問

systemctl restart httpd  這是時出現一個認證窗口 輸入用戶和密碼之後纔可以看到默認界面@@@@@@@@@@ Apache 的虛擬主機  @@@@@@@@@@@@

1 定義

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

(比如騰訊的一臺apache服務器掛了多個站點 news.qq.com money.qq.com www.qq.com  訪問這三個不同的域名分別出現新聞 財經 和主頁面 但這三個頁面的是一樣的 即一臺apache服務器再被訪問不同域名時會出現不同的頁面)

 

2 建立測試頁

mkdir /var/www/virtual/money.westos.com/html -p

mkdir /var/www/virtual/news.westos.com/html -p

echo "money.westos.com's page">/var/www/virtual/money.westos.com/html/index.html

echo "news.westos.com's page">/var/www/virtual/news.westos.com/html/index.html

## echo 是寫測試頁面

 

配置

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

<Virtualhost   _default_:80>        虛擬主機開啓的端口80

    DocumentRoot "/var/www/html"虛擬主機的默認發佈目錄

    CustomLog "logs/default.log" combined 虛擬主機日誌 combined記錄所有日誌

</Virtualhost>

 

vim /etc/httpd/conf.d/money.conf指定域名money.westos.com的訪問都到指定默認發佈目錄中

<Virtualhost *:80>

    ServerName "money.westos.com"

    DocumentRoot "/var/www/virtual/money.westos.com/html"

    CustomLog "logs/news.log" combined

</Virtualhost>

<Directory "/var/www/virtual/money.westos.com/html">  對默認發佈目錄授權

    Require all granted  給目錄做訪問授權 不然輸域名是找不到指定目錄的 所有人訪問

</Directory>             這個目錄都有權限

 

vim /etc/httpd/conf.d/news.conf

 29 <Virtualhost *:80>

 30     ServerName "news.westos.com"

 31     DocumentRoot "/var/www/virtual/news.westos.com/html"

 32     CustomLog "logs/news.log" combined

 33 </Virtualhost>

 34 <Directory "/var/www/virtual/news.westos.com/html">

 35     Require all granted

 36 </Directory>

 

4測試

在瀏覽器所在主機中 vim /etc/hosts 做域名解析

www.westos.com money.westos.com news.westos.com

在瀏覽器上輸www.westos.com會看到他的測試頁面 輸menoy.westos.com會看到money.westos.com's page 字樣 輸news.westos.com 會看到news.westos.com字樣的頁面

 

 

@@@@@@@@@@@@@@@  https  @@@@@@@@@@@@@@@@

1 https定義

Hyper text transter protocol over secure socker layer

通過ssl

 

http(明文訪問) https(加密訪問) (銀行優盾是加密的,將數據包加密發送到銀行服務器 銀行在解密看數據包 防止抓包 放置信息泄露 用鎖加密用證書解密 )

http-https 端口由80變成443 需要ssl插件

2 配置

yum install -y mod_ssl crypto-utils

genkey www.westos.com   給自定義的頁面加鎖成https

/etc/pki/tls/private/www.westos.com.key

/etc/pki/tls/cert/www.westos.com.crt  

產生一個鑰匙和一個證書

 

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

<Virtualhost *:443>

        ServerName "login.westos.com"

        DocumentRoot "/var/www/virtual/login.westos.com/html"

        CustomLog "log/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>  網頁重寫實現自動訪問https

        ServerName login.westos.com

        RewriteEngine on

        RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]

</Virtualhost>

 

註釋:

RewriteRule ^(/.*)$ 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

寫測試頁 login.westos.com

systemctl restart httpd

 

測試:

在客戶端主機添加解析   

vim /etc/hosts    172.25.254.70  login.westos.com

 

訪問http://login.westos.com 會自動跳轉到

https://login.westos.com 實現頁面數據加密傳輸


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章