歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> 關於 Apache 的幾種常見應用舉例與分析

關於 Apache 的幾種常見應用舉例與分析

日期:2017/2/27 9:40:09   编辑:更多Linux

A.如何為每個用戶設置單獨的主頁?
  默認設置情況下,你需要在你的用戶主目錄中創建目錄public_Html,然後把你的所有網頁文件放在該目錄下即可,打入http://servername/~username訪問,但是請注意以下幾點:
  
  1.登錄為root,修改用戶主目錄權限(#chmod 705 /home/username),讓其他人有權進入該目錄浏覽。
  2.以自己的用戶名登錄,創建public_html目錄,保證該目錄也有正確的權限讓其他人進入。
  3. Apache默認的主頁文件是index.html,不是index.htm,你可以改變/etc/mime.types文件中的一行象下面。
  text/html html htm
  然後Apache會讀你的index.htm文件4.用戶自己在主目錄下創建的目錄最好把權限設為0700,確保其他人不能進入訪問。
  
  B.如何設虛擬主機?
  1.假設某台服務器IP為192.168.11.2,要虛擬另一IP address為192.168.11.4,則加下面的行到/etc/rc.d/rc.local
  /sbin/ifconfig eth0:0 192.168.11.4 /sbin/route add -host 192.168.11.4 eth0:0
  2.加下面的行到/home/httpd/conf/httpd.conf
  VirtualHost 192.168.11.4 (此行有<>)
  ServerAdmin your_email_address
  DocumentRoot /home/httpd/foldername
  ServerName virtualservername
  ErrorLog /var/log/httpd/foldername/error.log
  TransferLog /var/log/httpd/foldername/Access_log/VirtualHost (此行有<>)
  3.若在你的LAN中有DNS服務器,加上相應的項192.168.11.4--->virtualservername
  
  C.如何用Apache給某個目錄以密碼保護?
  默認情況下,可在某個目錄下放一個文件.htaccess,象下面這樣:
  
  AuthName stuff
  AuthType Basic
  AuthUserFile /etc/.userpasswd
  require valid-user
  為了給用戶user1進入訪問,用# htpasswd -c /etc/.userpasswd user1為user1分配密碼。
  
  D.如何把某個目錄共享出來用浏覽器訪問?如/home/FTP/pub/
  1.加下面的行到/home/httpd/conf/srm.confAlias /pub /home/ftp/pub/2.更改默認文件類型,改/home/httpd/conf/srm.conf中一行為:
  DefaultType application/octet-stream 3.重新啟動Apache. /etc/rc.d/init.d/httpd restar




Copyright © Linux教程網 All Rights Reserved