| 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 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 跳转时为了让搜索引擎更快的找到 |
原文:http://www.cnblogs.com/zhaofuyun/p/5094843.html