Apache用戶認證、默認虛擬主機、域名301跳轉

apache hosts配置文件:apache

vim /usr/local/apache/conf/extra/httpd-vhosts.confvim

apache 主配置文件:windows

vim /usr/local/apache/conf/httpd.confide

apache命令:ui

vim /etc/profile.d/path.sh    ##設置apache環境spa

apachectl -t(檢查配置文件是否有錯) -M(檢查模塊是否加載) graceful(從新加載)start(啓動)restart(重啓)rest


 vim /usr/local/apache/conf/extra/httpd-vhosts.confblog

##默認虛擬記住配置:ip

<VirtualHost *:80>
DocumentRoot "/tmp/123"
ServerName 1232.com
</VirtualHost>域名


##80端口配置

<VirtualHost *:80>

DocumentRoot "/data/www"
ServerName www.test.com
ServerAlias www.cc.com
ServerAlias www.aa.com

# ErrorLog "logs/dummy-host.example.com-error_log"
# CustomLog "logs/dummy-host.example.com-access_log" common

##301跳轉模塊
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.cc.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.aa.com$
RewriteRule ^/(.*)$ http://www.test.com/$1 [R=301,L]
</IfModule>

##用戶認證模塊

<Directory /data/www/abc/>
AllowOverride AuthConfig
AuthName "的"
AuthType Basic
AuthUserFile /data/.htpasswd
require valid-user
</Directory>

</VirtualHost>


 

vim /usr/local/apache/conf/httpd.conf

     啓用apache 的hosts功能

   啓用該模塊可實現跳轉

   apachectl -M   檢查是否加載該模塊

 

 

 


 總結:

1.全部模塊的添加都是在80端口模塊下完成的
2.每一個域名的跳轉,都須要將該域名加在80端口下,ServerAlias是能夠寫多個的
3.windows下也須要將跳轉的域名加到hosts下
4.檢查rewrite模塊是否加載:apachectl -M
5.以上都沒有問題的時候還有403,則須要清除規則iptables -F
注:每次編輯完httpd-vhosts.conf,記得檢查是否有錯apachectl -t,而後從新加載apachectl graceful。

相關文章
相關標籤/搜索