apache用戶認證、默認主機、301跳轉

我更正論壇一個同窗帖子(今天坑我一下午):原文http://www.apelearn.com/bbs/foru ... 3%BB%A7%C8%CF%D6%A4

apache用戶認證、默認主機、301跳轉
Apache用戶認證
用vim打開/usr/local/apache2/conf/extra/httpd-vhosts.conf文件
<Directory /data/www/abc/>
        AllowoVerride Authconfig
        Authname "ni hao xian sheng"
        AuthType Basic
        AuthUserfile /data/.htpasswd
        Require valid user【此處確定坑了很多人應爲:Require valid-user 少了「-」,apache訪問控制不能正常加載: /data/.htpasswd】
</Directory>
而後重新加載一下apache就能夠le
1.##  這裏設置的目錄爲真實目錄,並不是虛擬目錄
2.    AllowOverride AuthConfig  爲容許認證
3.    AuthType  認證類型 Basic 由 mod_auth 提供
4.    AuthName  這裏定義的內容將在 web 彈出的登錄框中顯示
5.    AuthUserFile  定義認證文件路徑 ,不要放在可能被下載到的地方
6.    Require user  定義容許訪問的用戶
配置完這一步接下來創建驗證文件
Htpsswd -c /data/.htpasswd malong (若是要在添加一個用戶的話不加c選項)
New password: 
Re-type new password: 
配置默認虛擬主機
用vim打開/usr/local/apache2/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
    ServerAdmin webmaster@dummy-host.example.com
    DocumentRoot "/tmp/123"
    ServerName www.23.com
    #ServerAlias www.meiqianzenmeweihuganqing.com
  #  ErrorLog "logs/dummy-host.example.com-error_log"
#   CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
指定一個不存在的目錄DocumentRoot 在/tmp/下建立123 (防止起啓動的時候報錯) /tmp/而後在下降文件的的權限 chmod 600 /tmp/123這樣就不會訪問到的,其目的是爲了安全、只容許指定的域名訪問。
301域名跳轉的配置
用vim /usr/local/apache2/conf/extra/httpd-vhosts.conf中進行配置
<VirtualHost *:80>
     ServerName www.xxx.com
     ServerAlias www.yyy.com
     DocumentRoot /var/www/html/aminglinux
     RewriteEngine on
     RewriteCond %{HTTP_HOST} ^www.aaa.com$(條件)
     RewriteRule ^(.*)$ http://www.yyy.com$1 [R=permanent,L]或[R=301,L](規則)301永久從定向302臨時重定向L表示結束了

</VirtualHost>
多域名時在條件後面加[OR]或者的意思
在linux中用curl進行測試命令格式 curl -xip 域名 -I
跳轉時爲了讓搜索引擎更快的找到php

相關文章
相關標籤/搜索