天天看點

Apache服務

(1) 安裝Apache

  <1> 下載下傳Apache源碼檔案

    wget  http://mirror.bit.edu.cn/apache//httpd/httpd-2.2.34.tar.gz

    注釋:

               如果提示-bash: wget : command  not found  請安裝 yum install wget

(2) 解壓httpd檔案

   <1> 下載下傳的壓縮檔案,預設存放在Linux的根目錄下

   <2> tar -xzf   解壓tar.gz的檔案       tar -xjf   解壓tar.bz2的檔案

(3) ./configure(預編譯)

  <1> 進入Apache安裝目錄  cd   httpd-2.2.34

  <2>  ./configure --prefix=/usr/local/apache2/ --enable-rewrite  --enable-so  --enable-ssl

 注釋:

        預編譯過程中,如果出現

              configure:error: in `/usr/local/src/httpd-2.2.21/srclib/apr':

              configure:error:

             no acceptable C compiler found in $PATH

 解決辦法是安裝 yum  install gcc -y

       預編譯的過程中,如果出現,no SSL-C headers found

configure: error: ...No recognized SSL/TLS toolkit detected

解決辦法是 yum install  openssl-devel   -y

<4> make  (編譯)

<5>  make  install (安裝)

(4) 預編譯時,Apache被安裝在 /usr/local/Apache2目錄下

  <1> Apache的主配置檔案

     ①   [root@localhost apache2]# cd conf

      ②  [root@localhost apache2]# cat httpd.conf

   注釋: httpd.conf是Apache的主配置檔案

 ★ apache配置檔案解析:

    ServerRoot "/usr/local/apache2/"   apache服務的根目錄

    Listen 80  apache監聽的是80端口

    ServerAdmin [email protected] 管理者郵箱

    DocumentRoot "/usr/local/apache2//htdocs" 網站根目錄

     對apache根目錄做的權限設定

    <Directory />

           Options FollowSymLinks

           AllowOverride None

           Order deny,allow

           Deny from all

</Directory>

  對網站根目錄做的權限設定

<Directory "/usr/local/apache2//htdocs">

        Options Indexes FollowSymLinks

         注釋:

                   如果網站根目錄下沒有預設首頁,會把網站根目錄下所有的檔案都羅列出來

                   如果沒有Indexes,會報權限被拒絕

        AllowOverride None

        Order allow,deny

        Allow from all      

設定網站的預設首頁

<IfModule dir_module>

    DirectoryIndex index.html

</IfModule>

對.htaccess做的權限設定

<FilesMatch "^\.ht">

    Order allow,deny

    Deny from all

    Satisfy All

</FilesMatch>

ErrorLog "logs/error_log"  錯誤日志路徑

LogLevel warn  日志記錄的級别

Include conf/extra/httpd-vhosts.conf  Include檔案設定

對ssl的配置

<IfModule ssl_module>

SSLRandomSeed startup builtin

SSLRandomSeed connect builtin

   <2> Apache的啟動檔案

    ① [root@localhost apache2]# cd bin

  注釋: httpd  apachectl 是apache的啟動檔案

(5) Apache監聽的是80端口

Apache服務

(6) Apache釋出網站的根目錄

   /usr/local/apache2/htdocs

(7) 啟動Apache

  ① /usr/local/apache2/bin/apachectl start

  ② /usr/local/apache2/bin/httpd -k start  | graceful (平滑重新開機)

  ③

        重新開機apache進行檢查 /usr/local/apache2/bin/apachectl -t

        如果出現Syntax ok  表示apache配置沒有錯誤

        Apache啟動遇到的錯誤總結       

apache2: Could not reliably determine the server's fully qualified domain name 解決方法

 在 vim  httpd.conf  配置檔案中, 加入ServerName localhost:80

(8) 通路伺服器ip ,檢視通路是否成功

(9) 過濾 http.conf配置檔案中的空格和#号

   ① grep -v "#" httpd.conf | grep -v "^$" >> httpd.conf.bak

   ② mv httpd.conf.bak  httpd.conf

(10) 檢視Apache程序是否啟動    ps -ef | grep  httpd  

(11) 檢視Apache端口是否監聽  netstat -ntl  | grep 80

------------------------------  apache虛拟主機配置-----------------------------------------------

(1) apache虛拟主機就是在一個ip位址上配置了多個域名,我們通過域名來通路,域名通路的前提是要進行DNS解析,把ip位址和域名對應起來。作業系統規定,在進行DNS請求以前,先檢查自己的hosts檔案中是否有ip位址的映射關系,如果沒有,在像DNS發出解析請求

(2) hosts檔案路徑 c:\\windows\System32\drivers\etc

(3) 把ip位址和要解析的域名放到hosts檔案中即可實作解析

(4) 配置虛拟主機

   ① 進入虛拟主機配置目錄(httpd-vhosts.conf是虛拟主機配置檔案)

      [root@localhost apache2]# cd conf

      [root@localhost conf]# cd extra

      [root@localhost extra]# cat httpd-vhosts.conf

  ② 修改配置檔案

  NameVirtualHost *:80  虛拟主機監聽本地網卡的80端口

<VirtualHost *:80>        虛拟主機配置開始

    ServerAdmin [email protected]   管理者郵箱

    DocumentRoot "/usr/local/apache2/htdocs/jf1"  網站釋出的根目錄

    ServerName www.jf1.com      虛拟主機的域名

    ErrorLog "logs/www.jf1.com-error_log"     錯誤日志的路徑及檔案名

    CustomLog "logs/www.jf1.com-access_log" common  日志的路徑及檔案名

</VirtualHost> 虛拟主機配置結束

③ 建立www.jf1.com  和  www.jf2.com的釋出目錄

  mkdir -p /usr/local/apache2/htdocs/jf1     mkdir -p /usr/local/apache2/htdocs/jf2

④ 在2個釋出目錄下,分别建立index.html檔案

⑤ 在httpd.conf配置檔案中引入httpd-vhosts.conf配置檔案

   Include conf/extra/httpd-vhosts.conf

⑥ 重新開機網卡,驗證配置結果

  /usr/local/apache2/bin/httpd -k start

--------------------------------- apache虛拟主機企業配置方式------------------------------------

① 在htppd.conf配置檔案中,引入 Include conf/vhosts/*

② 建立vhosts目錄  mkdir vhosts

③ 在vhosts目錄下把虛拟主機配置檔案拷貝過來

④ 拷貝的虛拟主機配置檔案,去掉NameVirtualHost *:80

⑤ 在httpd.conf配置檔案中,把NameVirtualHost *:80添加上

⑥ 重新開機apache驗證配置結果