11.18-11.21 Apache user authentication, domain jump, Apache access log

Source: Internet
Author: User
Tags md5 encryption apache access log

11.18Apache user Authentication

Copy the corresponding parameters into the second virtual host (a second virtual host is selected in order not to affect the default host use)

<Directory/data/wwwroot/www.123.com>//Designation of certified directories

AllowOverride authconfig//This equivalent to open the authentication switch

AuthName "123.com user auth"//Custom certified name, not very useful

AuthType Basic//authentication type, generally basic, other types of Amin useless

AUTHUSERFILE/DATA/.HTPASSWD//Specify the location of the password file

Require Valid-user//specify that users who require authentication are all available users

</Directory>

[Email protected] wwwroot]# vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf

After modification

After the configuration is complete, you need to create a password file

#/usr/local/apache2.4/bin/htpasswd-c-M/DATA/.HTPASSWD aming

Explanation of the previous command:

HTPASSWD tool,-c creation,-M MD5 encryption, followed by password file./htpasswd to pick up the user.

[Email protected] wwwroot]# LS/DATA/.HTPASSWD

/data/.htpasswd

Can be a cat password file, is a string of code, because it was MD5 encrypted.

[Email protected] wwwroot]# CAT/DATA/.HTPASSWD

Aming: $apr 1$5mmrmcox$e0qy/azyyojxzy0jtlsxt1

* Note: If you need to increase the user again, cancel-C because-C is created and generated, if you use the-C will be overwritten.

[Email protected] wwwroot]#/usr/local/apache2.4/bin/htpasswd-m/data/.htpasswd Zhangsan

/usr/

After you set the password,

Reload config-T, graceful

#curl检视信息, 401 indicates that this page needs to be validated.

After the configuration is complete, you need to change the Hosts file (C:\WINDOWS\SYSTEM32\DRIVERS\ETC) to the real machine Windows, add the URL

Login the correct account password to verify success

If you want to authenticate a single file, you can do so.

#vim/data/wwwroot/111.com/123.php

Reload config-T, graceful

Once completed, login 111.com/123.php requires authentication, and 111.com does not require authentication.


11.19 11.20 Domain name 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.com

Serveralias 123.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 rules that are not executed until the above conditions are met

</IfModule>

</VirtualHost>

/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) #

Curl-x127.0.0.1:80-i 123.com//Status Code 301


11.21 Configuring access Logs

Access log records every request from a user

vim/usr/local/apache2.4/conf/httpd.conf//Search Logformat

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

Curl-x127.0.0.1:80-i 123.com

Tail/usr/local/apache2.4/logs/123.com-access_log


11.18-11.21 Apache user authentication, domain jump, Apache 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.