歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> 用實驗快速掌握web服務器Apache

用實驗快速掌握web服務器Apache

日期:2017/2/27 14:24:16   编辑:更多Linux
  Apache是大多數Linux版本的標准web 服務器,掌握他的意義就非常大。    本文以實驗的方式,讓讀者快速掌握Apache的基本配置。    [實驗目的]    1.Apache的基本安裝和配置。    2.Apache中應用CGI。    3.基本代理配置。    [實驗要求]    1.兩台互通的RH8.0機。    2.這兩台機已配置過DNS。    [實驗步驟]    1.准備工作。    由於web 服務器與DNS關系非常緊密。作好這步准備工作。    “用實驗快速掌握DNS配置”。這篇文章發表在linuxsir的網絡版塊。    DNS 能夠實現的主要功能就是能能解析:station1.exmaple1.com,server1.example1.com 兩個域名的IP,如果你想在/etc/hosts中實現,我想也不是不可以。這裡不提倡這麼做。    本文中作法比較教條,這裡指明機器1為:server1.example1.com,機器2為:    station1.example1.com .讀者也可以自己變通。    2.在機器1上安裝和配置簡單的Apache。    1) 檢查下列包是否安裝,    httpd  httpd-manual    缺什麼,裝什麼。    2) 開啟httpd服務    # service httpd start    如果開啟失敗,查看/var/log/httpd/下的相關日志,切記要在/etc/hosts中添加類似    192.168.0.254 example1.com server1 的一行。    3) 檢查/etc/httpd/conf/httpd.conf中,有下列一行活動    DocumentRoot /var/www/Html    4) 用一個浏覽器打開:    http://server1.example1.com    如果是正常情況,你會看到Apache的介紹頁面。    5) 創建新的目錄和html文件。    # mkdir -p /var/www/virtual/server1.example1.com/html  # vi /var/www/virtual/server1.example1.com/html/index.html  Server1.example1.com    6) 編輯/etc/httpd/conf/httpd.conf,末尾追加下列文本。    NameVirtualHost 192.168.0.254    ServerName server1.example1.com  ServerAdmin [email protected]  DocumentRoot /var/www/virtual/server1.example1.com/html  ErrorLog logs/server1.example1.com-error_log  CustomLog logs/server1.example1.com-Access_log combined    Options Indexes Includes    7) 確保DNS能夠解析你的VirtualHost    # host server1.example1.com    8) 重新啟動httpd    # service httpd restart    如果啟動失敗,看/var/log/httpd/下的相應日志,會告訴你具體哪裡錯誤。    9) 在浏覽器裡能夠看到你自己寫的網頁了嗎?    http://server1.example1.com    10) 在機器2上能看到http://server1.example1.com嗎?    3.機器1,在Apache中應用CGI    1) 編輯/etc/httpd/conf/httpd.conf,在塊中添加下列一行:    ScriptAlias /cgi-bin/ /var/www/virtual/server1.example1.com/cgi-bin/    2) 創建目錄,創建文件。    # mkdir /var/www/virtual/server1.example1.com/cgi-bin  #vi /var/www/virtual/server1.example1.com/cgi-bin/test.sh    #!/bin/bash  echo Content-Type: text/html  echo    echo “”  echo My username is :  whoami  echo  echo My id i??獡s?? ???!s :  id  echo  echo Here is /etc/passwd :  cat /etc/passwd  echo “”    3) 改變test.sh的執行權限:    # chmod 555 test.sh    4) 重啟httpd服務:    # service httpd restart    若有錯,看日志。    5) 浏覽:http://server1.example1.com/cgi-bin/test.sh    6) 機器2能浏覽http://server1.example1.com/cgi-bin/test.sh嗎?    4.基本代理配置:    1) 機器1,檢查squid 包裝了沒有,沒有的話,則進行安裝。    2) 機器1,啟動squid 服務。    # service squid start    有問題? 看/var/log/messages.    3) 機器1,浏覽器中設置代理端口為3128,舉例:在mozilla: Edit Preferences...    Advanced proxies 中,設定手動,端口為:3128,其他不動。    機器2,浏覽器中類似設置為:手動,http代理:192.168.0.254 端口:3128。    4) 此時,機器1,能浏覽server1.exmaple1.com.,若平時能上internet,此時也正常上internet。    5) 機器2,不能浏覽server1.example1.com 或internet。    查看/var/log/httpd/*的日志文件,原因是什麼?    6) 編輯/etc/squid/squid.conf,在acl CONNECT method CONNECT行下,添加下列一行:    acl examample1 src 192.168.0.0/24    找到INSERT YOUR OWN RULE(S) HERE 增加下列一行:    http_access allow example1    7) 重啟squid    # service squid restart    有錯?看日志。    8) 此時,機器2能夠浏覽server1.example1.com 或 internet網頁.    9) 編輯/etc/squid/squid.conf ,在acl examample1 src 192.168.0.0/24行下添加    acl otherdeny dstdomain .sina.com.cn    在http_access allow example1下添加:    http_access deny otherdeny    10) 重啟squid.    # service squid restart    有錯? 看日志。    11) 機器2,仍能浏覽 http://www.sina.com.cn,為什麼    12) 編輯/etc/squid/squid.conf ,把http_access deny otherdeny放到    http_access allow example1前面,重啟squid,機器2還能看到    http://www.sina.com.cn嗎    [實驗總結]    Apache配置是否成功,與DNS有很大關系,所以,要求讀者先花時間作好DNS工作。本文    以最通俗的方式,教你簡單的配置Apache,如果想深入掌握它,還得研究Apache2.0的文檔。




Copyright © Linux教程網 All Rights Reserved