One, Apache user authentication
vim/usr/local/apache/conf/extra/httpd-vhosts.conf//The 11.com virtual host is edited into the following content
<virtualhost *:80>
DocumentRoot "/data/wwwroot/www.123.com"
ServerName www.123.com
<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>
To generate a password file after the modification is complete
2. Generate password file:/usr/local/apache/bin/htpasswd-c-m/data/.htpasswd Riven
Then enter the password you want. The password file is then generated
-C Create
-m Specifies the type of encryption
If you want to add more users, you don't need the-c option.
Reload configuration/usr/local/apache/bin/apachectl-t, graceful
Binding hosts, browser testing
Then we use curl-x192.168.1.31:80 11.com to access, prompt 401, stating that you access the content needs to do user authentication
How do we use Curl-x to access user-certified websites?
curl-x192.168.1.31:80-uriven:1122 11.com
Tip 200 indicates successful access
3. Authentication for individual files
<virtualhost *:80>
DocumentRoot "/data/wwwroot/www.123.com"
ServerName www.123.com
<filesmatch admin.php>//We specified the entire directory earlier, and now we specify a single page.
AllowOverride authconfig
AuthName "123.com User auth"
AuthType Basic
authuserfile/data/.htpasswd
Require Valid-user
</FilesMatch>
</VirtualHost>
Second, the domain name jump (301 permanent Redirect, increase the weight)
1. Example: Jump 11.com domain name to www.123.com, configure as follows:
<virtualhost :80>
DocumentRoot "/data/wwwroot/www.123.com"
ServerName 11.com
Serveralias 123.com
<ifmodule mod_rewrite.c>//requires Mod_rewrite module support
Rewriteengine on//Open rewrite function
Rewritecond%{http_host}!^11.com$//define rewrite condition, hostname (domain name) is not 11.com meet condition
Rewriterule ^/(.) $ http://11.com/$1 [r=301,l]//define rewrite rules that will be executed when the above conditions are met
</IfModule>
</VirtualHost>
302 is temporary redirection.
/usr/local/apache/bin/apachectl-t
/usr/local/apache/bin/apachectl-m |grep rewrite see if the rewrite module is loaded
If you do not have the module, you need to edit the configuration file httpd.conf, delete rewrite_module (shared) in front of the #
2. Test
Curl-x127.0.0.1:80-i 123.com-i//Status code is 301
Third, Apache access log
1. Access logging records every request from a user
2. Define the format for the log
vim/usr/local/apache/conf/httpd.conf//Search for Logformat, it gives you two formats:
Logformat "%h%l%u%t \"%r\ "%>s%b \"%{referer}i\ "\"%{user-agent}i\ "" combined
Logformat "%h%l%u%t \"%r\ "%>s%b" common
(user-agent user agent, Referer is the URL that the browser visited once.) )
Change the virtual host configuration file to the following:
<virtualhost *:80>
DocumentRoot "/data/wwwroot/www.123.com"
ServerName 11.com
Serveralias 123.com
Customlog "Logs/11.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
Dizzy, write again tomorrow! Feel too much content
Apache user authentication and domain name jump, access log