编译安装apache后的目录文件:/usr/local/apache2

1:用户认证

主配置目录:/usr/local/apache2/conf/

1)建立目录并设置用户认证:

Alias  /1.php/ “/usr/local/apache2/htdocs/1.php”    

    AllowOverride None

    Options None

    Order allow,deny

    Deny from all

    AuthType Basic

    AuthName "Please Login:"

    AuthUserFile /usr/local/apache2/bin/mywebpd   #存密码的目录

    Require User root  tong     #用户

centos7编译安装apache后添加用户认证和配置虚拟主机_第1张图片

centos7编译安装apache后添加用户认证和配置虚拟主机_第2张图片

2:配置虚拟主机/usr/local/apache2/conf/extra/httpd-vhosts.conf

配置基于IP的虚拟主机,IP地址相同,但端口号不同的虚拟主机配置,

虚拟主机分别对应的目录为/usr/local/apache/htdocs/web1和/usr/local/apache/htdocs/web2:

Listen 80

#Listen 8080

  ServerSignature  email

  DocumentRoot /usr/local/apache/htdocs/web1

  DirectoryIndex  web1.html

  LogLevel warm

  HostNameLookups  off

  ServerSignature  email

  DocumentRoot /usr/local/apache/htdocs/web2

  DirectoryIndex  web2.html index.htm

  LogLevel warm

  HostNameLookups  off

效果图:

centos7编译安装apache后添加用户认证和配置虚拟主机_第3张图片