apache用户认证、默认主机、301跳转

回复 收藏
Apache用户认证
用vim打开/usr/local/apache2/conf/extra/httpd-vhosts.conf文件

        AllowoVerride Authconfig
        Authname "ni hao xian sheng"
        AuthType Basic
        AuthUserfile /data/.htpasswd
        Require valid-user

然后从新加载一下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

    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

指定一个不存在的目录DocumentRoot 在/tmp/下创建123 (防止起启动的时候报错) /tmp/然后在降低文件的的权限 chmod 600 /tmp/123这样就不会访问到的,其目的是为了安全、只允许指定的域名访问。
301域名跳转的配置
用vim /usr/local/apache2/conf/extra/httpd-vhosts.conf中进行配置

ServerNamewww.xxx.com
ServerAliaswww.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表示结束了


多域名时在条件后面加[OR]或者的意思
在linux中用curl进行测试命令格式 curl -xip 域名 -I
跳转时为了让搜索引擎更快的找到
2015-12-13 16:01 举报
已邀请:

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: