HTTP user authentication, domain jump, access log

Source: Internet
Author: User
Tags apache access log

User authentication for HTTPD
  • Special pages of the site require level two certification
  • vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf//Edit 111.com Virtual Host

    <VirtualHost *:80>DocumentRoot "/data/wwwroot/111.com"ServerName 111.com<Directory /data/wwwroot/111.com> #//指定认证的目录    AllowOverride AuthConfig #//这个相当于打开认证的开关    AuthName "111.com user auth" #//自定义认证的名字,作用不大    AuthType Basic #//认证的类型,一般为Basic,其他类型阿铭没用过    AuthUserFile /data/.htpasswd  #//指定密码文件所在位置    require valid-user #//指定需要认证的用户为全部可用用户</Directory></VirtualHost>
  • /USR/LOCAL/APACHE2.4/BIN/HTPASSWD-CM/DATA/.HTPASSWD aming//create/data/.htpasswd password file and add user aming, set password to MD5 encryption.

    [[email protected] ~]#  /usr/local/apache2.4/bin/htpasswd -cm /data/.htpasswd aming New password: Re-type new password: Adding password for user aming[[email protected] ~]# cat /data/.htpasswd aming:$apr1$IcrnKsgm$peDVR4iChx.0E9/zaD.HK.
  • /usr/local/apache2.4/bin/apachectl-t
  • /usr/local/apache2.4/bin/apachectl Graceful
  • Test

    [[email protected] ~]# curl -x127.0.0.1:80 -uaming:123456 111.com111.com[[email protected] ~]# curl -x127.0.0.1:80 111.com -IHTTP/1.1 401 Unauthorized   
  • Authentication of individual files
    <VirtualHost *:80>DocumentRoot "/data/wwwroot/www.123.com"ServerName www.123.com<FilesMatch admin.php>          #//对admin.php页面进行认证    AllowOverride AuthConfig    AuthName "123.com user auth"    AuthType Basic    AuthUserFile /data/.htpasswd    require valid-user</FilesMatch></VirtualHost>
Domain Jump
  • requirements, the 123.com domain name jump to www.123.com, configured as follows:

    <VirtualHost *:80>DocumentRoot "/data/wwwroot/www.123.com"ServerName www.123.comServerAlias 123.com<IfModule mod_rewrite.c> //需要mod_rewrite模块支持    RewriteEngine on  //打开rewrite功能    RewriteCond %{HTTP_HOST} !^www.123.com$  //定义rewrite的条件,主机名(域名)不是www.123.com满足条件    
  • /usr/local/apache2/bin/apachectl-m|grep-i rewrite//Without this module, you need to edit the configuration file httpd.conf, delete the front of the Rewrite_module (shared) #
  • Reload config-T, graceful
  • Curl-x127.0.0.1:80-i 123.com//Status code is 301 permanent jump, 302 temporary jump, 401 need to verify, 404 page does not exist, 403 is not authorized, Apache access log records every request of the user
  • vim/usr/local/apache2.4/conf/httpd.conf//Search Logformat

    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combinedLogFormat "%h %l %u %t \"%r\" %>s %b" common 默认是common,改为combined,h来源ip,u用户,t是时间,r行为,s是状态码,b是大小,Referer是进入当前页面得上一个页面得地址,User-Agent用户代理即用户使用的浏览器,curl命令等
  • Change the virtual host configuration file to the following:

    <VirtualHost *:80>DocumentRoot "/data/wwwroot/www.123.com"ServerName www.123.comServerAlias 123.comCustomLog "logs/123.com-access_log" combined</VirtualHost>
  • Reload the configuration file-t,graceful
  • Curl-x127.0.0.1:80-i 123.com
  • Tail/usr/local/apache2.4/logs/123.com-access_log
Extended
    • Apache Virtual host opens PHP's short tag

HTTP user authentication, domain jump, access log

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.