41, Apache user authentication, domain name jump, access log

Source: Internet
Author: User
Tags curl md5 encryption

One, Apache user authentication
    • 1. Encrypt directory
        vim/usr/local/apache2.4/bin/apachectl start  
        vim/usr/local/ apache2.4/conf/extra/httpd-vhosts.conf//123.com that virtual host edited into the following  

      <virtualhost *:80>
      DocumentRoot "/data/wwwroot/www.123.com"
      ServerName www.123.com
      <Directory/data/wwwroot/123.com>// Specify the directory of authentication
      AllowOverride authconfig//This equivalent to open the authentication switch
      authname "123.com user auth"//Custom authentication name, less function
      AuthType Basic/ /authentication type, generally basic
      authuserfile/data/.htpasswd//Specify password file location
      require Valid-user//specify that users requiring authentication are all available users
      </ Directory>
      </virtualhost>

    • as follows, modified on previous basis
        <Directory/data/wwwroot/123.com> allowoverride authconfig authname "123.com user auth" authtype Basic authuserfile/data/.htpasswd require
       Valid-user </directory>  

        curl-x127.0.0.1:80 123.com  

    • Create user Password
/usr/local/apache2.4/bin/htpasswd  -c -m /data/.htpasswd chinantfy
    • Create the/data/.htpasswd file and establish the user, password one MD5 encryption, and then add the user only need-m option
      /usr/local/apache2.4/bin/apachectl  -t /usr/local/apache2.4/bin/apachectl graceful

      Login Test with browser

      curl -x127.0.0.1:80 www.123.com //状态码为401curl -x127.0.0.1:80 -uaming:passwd www.123.com  -I //状态码为200


    • 2. Encryption of single files
      Change the previous configuration file to
      <FilesMatch admin.php>    AllowOverride AuthConfig    AuthName "123.com user auth"    AuthType Basic    AuthUserFile /data/.htpasswd    require valid-user</FilesMatch>


Then create the admin.php file

vim /data/wwwroot/123.com/admin.php

<?php
echo "Admin":

/usr/local/apache2.4/bin/apachectl  -t /usr/local/apache2.4/bin/apachectl graceful

Test with a browser

Second, the domain name jumps

requirements, the www.good.com domain name jumps to www.123.com, configured as follows:

vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf

<virtualhost :80>
DocumentRoot "/data/wwwroot/www.123.com"
ServerName www.123.com
Serveralias 123.com www.good.com
<ifmodule mod_rewrite.c>//requires Mod_rewrite module support
Rewriteengine on//Open rewrite function
Rewritecond%{http_host}!^www.123.com$//define rewrite condition, hostname (domain name) is not www.123.com meet condition
Rewriterule ^/(.
) $ http://www.123.com/$1 [r=301,l]//define rewrite rule, when the above conditions are met, this rule will only execute, 301 permanent Redirect, 302 temporary redirect, usually with 301
</IfModule>
</VirtualHost>

<IfModule mod_rewrite.c>         RewriteEngine on          RewriteCond %{HTTP_HOST} !^www.123.com$          RewriteRule ^/(.*)$ http://www.123.com/$1 [R=301,L] </IfModule>

/usr/local/apache2/bin/apachectl -M|grep -i rewrite //若无该模块,需要编辑配置文件httpd.conf,删除rewrite_module (shared) 前面的#

/usr/local/apache2.4/bin/apachectl  -t /usr/local/apache2.4/bin/apachectl graceful curl -x127.0.0.1:80 -I www.good.com //状态码为301

Third, access logs

Access log records every request from a user

You can see that the log is in two formats, before the default is common
Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" combined
Logformat "%h%l%u%t \"%r\ "%>s%b" common

Change the virtual host configuration file to the following:

<virtualhost *:80>
DocumentRoot "/data/wwwroot/www.123.com"
ServerName www.123.com
Serveralias 123.com
Customlog "Logs/123.com-access_log" combined
</VirtualHost>
Reload the configuration file-t,graceful

 /usr/local/apache2.4/bin/apachectl  -t /usr/local/apache2.4/bin/apachectl graceful


41, Apache user authentication, domain name 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.