apache的配置

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

</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 [email protected]

    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

跳轉時爲了讓搜索引擎更快的找到


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章