zoukankan      html  css  js  c++  java
  • 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
    跳转时为了让搜索引擎更快的找到

  • 相关阅读:
    eclipse版本、代号
    eclipse中jdk及编译器版本问题
    改变cmd命令行颜色
    mysql-installer-community-8.0.12.0的安装
    算法简介
    Java--将数据以文本形式导出
    安装MySQL
    网络配置
    电脑拷软件到其他设备
    探针设备
  • 原文地址:https://www.cnblogs.com/zhaofuyun/p/5094843.html
Copyright © 2011-2022 走看看