標籤:linux 營運 基礎學習
1、Apache服務安裝
[[email protected] ~]# yum install httpd -y[[email protected] ~]# systemctl restart httpd[[email protected] ~]# systemctl stopfirewalld.service
安裝完成之後你可以開啟你的瀏覽器,在網址部分輸入172.25.254.231(也就是你原生IP),會出現Apache的預設頁面。
650) this.width=650;" src="https://s3.51cto.com/wyfs02/M02/9E/A6/wKioL1mUHqyg3njIAAHOlAq2Ac0705.png" title="1.png" alt="wKioL1mUHqyg3njIAAHOlAq2Ac0705.png" />
2. 修改網站目錄和為網站目錄增加密要
2.1 產生密鑰
[[email protected] conf]# htpasswd -cm authfile adminNew password:Re-type new password:Adding password for user admin[[email protected] conf]# htpasswd -m authfile admin1#如果出現authfile這個檔案如果在添加使用者認證,則不需要增加-c參數。,New password:Re-type new password:Adding password for user admin1
3.2 修改網站目錄
[[email protected] conf]# vim /etc/httpd/conf/httpd.conf119 #DocumentRoot "/var/www/html"注釋掉上面預設的網站目錄DocumentRoot ,添加一行新的網站目錄。120 DocumentRoot"/test/lala/html"添加新的網站目錄/test/lala/html130 <Directory"/test/lala/html">131# Require all granted#允許任何人訪問網站目錄,在做這個實驗時,需要將他注釋掉132 AuthUserFile /etc/httpd/conf/authfile#添加一個密碼認證133 AuthName "please input you countand password"#在登陸網址時的提示134 AuthType basic#為基礎認證135 Require user admin#當注釋掉136行,只能使用admin密鑰#當注釋掉135行,使用任意密鑰都可以登陸136 Require valid-user137 </Directory>這時如果在訪問目錄則會出現如下頁面,讓你輸入密碼
3.3 修改網站目錄的上下文
[[email protected] html]# semanage fcontext -a -t httpd_sys_content_t ‘/test(/.*)?‘[[email protected] html]# restorecon -RvvF /testrestorecon reset /test contextunconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0restorecon reset /test/lala contextunconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0restorecon reset /test/lala/html contextunconfined_u:object_r:default_t:s0->system_u:object_r:httpd_sys_content_t:s0restorecon reset /test/lala/html/index.ht
如果這時你如果在訪問就會出現如下介面,讓你輸入密碼:
650) this.width=650;" src="https://s2.51cto.com/wyfs02/M01/9E/A5/wKioL1mUEoWTfcKsAAEL5bZ5Bhk451.png" title="2.png" width="500" height="221" border="0" hspace="0" vspace="0" style="width:500px;height:221px;" alt="wKioL1mUEoWTfcKsAAEL5bZ5Bhk451.png" />
3.修改預設的網站目錄的檔案
[[email protected] ~]# vim/etc/httpd/conf/httpd.conf
<IfModule dir_module> DirectoryIndexfei.html index.html #注意以空格隔開,從前往後,先找你的fei.html,在找你的index.html</IfModule>
4.虛擬機器主機的配置
4.1 在主設定檔中添加虛擬機器主機
在主設定檔中添加如下內容:
[[email protected] ~]# vim/etc/httpd/conf/httpd.conf<Virtualhost *:80> Servername www.fei.com DocumentRoot /var/www/fei/ CustomLog "logs/fei.log" combined</Virtualhost><Directory "/var/www/fei"> Require all granted</Directory> #下面是另一個虛擬機器主機的設定檔<Virtualhost *:80> Servername www.tian.com DocumentRoot /var/www/tian/ CustomLog "logs/tian.log"combined</Virtualhost><Directory "/var/www/tian"> Require all granted</Directory>
分別建立2個目錄為 /var/www/fei/和/var/www/tian/,分別為兩個虛擬機器主機的網站目錄,在下面建立fei.html 或者index.html,因為我們在前面添加了fei.index。
[[email protected] html]# mkdir /var/www/fei[[email protected] html]# mkdir /var/www/tian[[email protected] fei]# cat /var/www/tian/index.htmlthis is tian‘s virtulhost[[email protected] fei]# cat /var/www/fei/index.htmlthis is fei‘s virtulhost#在/etc/hosts中添加如下內容,增加本地DNS解析。[[email protected] ~]# vim /etc/hosts172.25.254.231 www.fei.com www.tian.com
4.2 在/etc/httpd/conf.d下面添加虛擬機器主機
還有一個添加虛擬機器主機的方法:分別在這個目錄下建立3個不同的檔案分別為預設網站目錄和兩個虛擬機器主機的網站目錄
[[email protected] conf.d]# pwd/etc/httpd/conf.d#這個是 虛擬機器主機的設定檔 [[email protected] conf.d]# vim fei.conf<Virtualhost *:80> Servername www.fei.com DocumentRoot /var/www/fei/ CustomLog "logs/fei.log" combined</Virtualhost><Directory "/var/www/fei"> Require all granted</Directory> #下面是www.tain.com的預設主控件設定檔 [[email protected] conf.d]# vim tian.conf<Virtualhost *:80> Servername www.tian.com DocumentRoot /var/www/tian/ CustomLog "logs/tian.log"combined</Virtualhost><Directory "/var/www/tian"> Require all granted</Directory>#這個是預設的設定檔,也就是你輸入172.25.254.231是訪問的頁面[[email protected] conf.d]# vim default.conf<Virtualhost _default_:80> DocumentRoot "/var/www/html/" CustomLog "logs/default.log" combind</Virtualhost>#注意:設定檔可以在兩個地方寫,下面的做法也是建立虛擬機器主機的目錄,寫index.html檔案。
650) this.width=650;" src="https://s5.51cto.com/wyfs02/M00/9E/A5/wKioL1mUFSOjsR82AABIGdcszqY418.png" title="3.png" alt="wKioL1mUFSOjsR82AABIGdcszqY418.png" />650) this.width=650;" src="https://s3.51cto.com/wyfs02/M01/9E/A5/wKioL1mUFUzTWxRdAABPayAKGUY817.png" title="4.png" width="335" height="179" border="0" hspace="0" vspace="0" style="width:335px;height:179px;" alt="wKioL1mUFUzTWxRdAABPayAKGUY817.png" />
5.https 的配置
5.1 軟體安裝
yum install mod_ssl -y#安裝https外掛程式,使你的apache支援https.yuminstall crypto-utils.x86_64 -y#安裝外掛程式產生鑰匙和鎖
5.2 產生認證
[[email protected] ~]# genkey www.westos.com/usr/bin/keyutil -c makecert -g 1024 -s"CN=www.westos.com, OU=linux, O=westos, L=xi‘an, ST=Shannxi, C=CN" -v1 -a -z /etc/pki/tls/.rand.3669 -o /etc/pki/tls/certs/www.westos.com.crt -k/etc/pki/tls/private/www.westos.com.keycmdstr: makecertcmd_CreateNewCertcommand: makecertkeysize = 1024 bitssubject = CN=www.westos.com, OU=linux,O=westos, L=xi‘an, ST=Shannxi, C=CNvalid for 1 monthsrandom seed from /etc/pki/tls/.rand.3669output will be written to/etc/pki/tls/certs/www.westos.com.crtoutput key written to/etc/pki/tls/private/www.westos.com.keyGenerating key. This may take a fewmoments...Made a keyOpened tmprequest for writing/usr/bin/keyutil Copying the cert pointerCreated a certificateWrote 882 bytes of encoded data to/etc/pki/tls/private/www.westos.com.keyWrote the key to:/etc/pki/tls/private/www.westos.com.key
這個頁面是我們要填寫的認證資訊,還有要注意的是在產生認證過程中不要想CN認證發你的認證,這個是收費的。
650) this.width=650;" src="https://s3.51cto.com/wyfs02/M02/9E/A5/wKioL1mUF9_TgDuCAAKv4Yk_lRk151.png" title="~D0G9OH]9C6K5~S%IRS60J5.png" width="500" height="345" border="0" hspace="0" vspace="0" style="width:500px;height:345px;" alt="wKioL1mUF9_TgDuCAAKv4Yk_lRk151.png" />
5.2 修改http設定檔
我的虛擬機器主機在主設定檔中,所以我要修改主設定檔中的虛擬機器主機配置
[[email protected] ~]# vim /etc/httpd/conf/httpd.conf<Virtualhost *:443> #將這個虛擬網站的連接埠改為434,因為HTTPS服務的連接埠在434 Servername www.fei.com DocumentRoot /var/www/fei/ CustomLog "logs/fei.log" combined SSLEngine on SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt #認證認證 SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key #鑰匙</Virtualhost>#下面是對網站的授權,允許任何人訪問<Directory "/var/www/fei"> Require all granted </Directory>#下面是對網站的二次更改<virtualhost *:80> ServerName www.fei.com RewriteEngine on RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1[redirect=301]</virtualhost>
5.3 修改https的設定檔
[[email protected] ~]# vim/etc/httpd/conf.d/ssl.conf101 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt109 SSLCertificateKeyFile/etc/pki/tls/private/www.westos.com.key
這時你在訪問www.fei.com, 現如下頁面自動將其轉換為HTTPS協議加密傳輸
650) this.width=650;" src="https://s5.51cto.com/wyfs02/M01/9E/A6/wKioL1mUGv7CJVN8AAEXOl9Q1iI483.png" title="5.png" width="500" height="303" border="0" hspace="0" vspace="0" style="width:500px;height:303px;" alt="wKioL1mUGv7CJVN8AAEXOl9Q1iI483.png" />
點擊I Understand rhe Risks,然後點擊Add Execption
650) this.width=650;" src="https://s5.51cto.com/wyfs02/M00/9E/A6/wKioL1mUG1LAR4vbAAEIiTZ7LRo180.png" title="6.png" width="500" height="270" border="0" hspace="0" vspace="0" style="width:500px;height:270px;" alt="wKioL1mUG1LAR4vbAAEIiTZ7LRo180.png" />
出現如下頁面,點擊 Get Certificate,然後在點擊Confirm Security Exception,就會出現如下頁面,也就是我們配置好的虛擬機器主機的頁面,不過他是https
650) this.width=650;" src="https://s5.51cto.com/wyfs02/M00/9E/A6/wKioL1mUG-HSEKO3AABLVJPZP7o370.png" title="8.png" alt="wKioL1mUG-HSEKO3AABLVJPZP7o370.png" />
我們的認證認證資訊也可以查看如
650) this.width=650;" src="https://s2.51cto.com/wyfs02/M01/9E/A6/wKioL1mUHDmSGRweAACpUSqqYjo606.png" title="9.png" width="500" height="382" border="0" hspace="0" vspace="0" style="width:500px;height:382px;" alt="wKioL1mUHDmSGRweAACpUSqqYjo606.png" />
6.Apache 正向 Proxy
6.1 修改你的server和client的網卡
修改你server的ip為其添加另一塊網卡為eth1Server 的網卡分別為etho:172.25.254.231 eth1 172.25.31.231Client的網卡ehh0:172.25.31.131
6.2 安裝代理軟體
在server 安裝代理軟體
[[email protected] ~]# yum install squid -y[[email protected] ~]# vim /etc/squid/squid.conf 56 http_access allow all 62 cache_dir ufs /var/spool/squid 100 16 256[[email protected] ~]# systemctl restart squid
開啟你的瀏覽器修改你的進階網路設定
650) this.width=650;" src="https://s3.51cto.com/wyfs02/M02/9E/A6/wKioL1mUHT-wXtf2AAEmIJ-hm8Q773.png" title="10.png" width="480" height="500" border="0" hspace="0" vspace="0" style="width:480px;height:500px;" alt="wKioL1mUHT-wXtf2AAEmIJ-hm8Q773.png" />
這時你的client就可以通過server訪問client訪問不到的172.25.254網段的Apache。
7. http 反向 Proxy(需要3台)
清除你瀏覽器中正向的設定,然後配server中的設定檔
[[email protected] ~]# vim /etc/squid/squid.conf 56http_access allow all 59http_port 80 vhost vport 60cache_peer 172.25.254.117 parent 80 0proxy-only #第三台伺服器的ip 62cache_dir ufs /var/spool/squid 100 16 256
關閉你server的apache,這時你用虛擬機器訪問172.25.31.231時就會訪問到172.25.254.117的網站。
本文出自 “13122323” 部落格,請務必保留此出處http://13132323.blog.51cto.com/13122323/1956866
Apache2.4 企業七簡單配置