One, Apache user authentication
Vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf
Edit the 111.com virtual host to the following:
<virtualhost *:80>
DocumentRoot "/data/wwwroot/www.111.com"
ServerName www.111.com
<Directory/data/wwwroot/www.111.com>//Designation of certified directories
AllowOverride authconfig//This equivalent to open the authentication switch
AuthName "111.com user auth"//Custom certified name, not very useful
AuthType Basic//authentication type, generally basic
AUTHUSERFILE/DATA/.HTPASSWD//Specify the location of the password file
Require Valid-user//specify that users who require authentication are all available users
</Directory>
</VirtualHost>
Generate new user, password, check for success,-C: Create
You can also add other users, you can see two users coexist, this time do not need-C, because has been created
Reload config-T, graceful bind hosts, browser test
CURL-X127.0.0.1:80 111.com//Status code 401: Description Access content requires user authentication
curl-x127.0.0.1:80 111.com-i Large I
Curl-x127.0.0.1:80-udavery mimA123 111.com//Status Code 200
Enter the password correctly so that you can access
You can also authenticate against a single file
<virtualhost *:80>
DocumentRoot "/data/wwwroot/www.123.com"
ServerName www.123.com
<filesmatch admin.php>
AllowOverride authconfig
AuthName "123.com User auth"
AuthType Basic
authuserfile/data/.htpasswd
Require Valid-user
</FilesMatch>
</VirtualHost>
Second, the domain name jumps
requirements, the www.123.com domain name jumps to 111.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}!^111.com$ Statement Description: Not 111.com//define rewrite conditions, hostname (domain name)
Not www.123.com meet the conditions
Rewriterule ^/(. *) $ http://www.123.com/$1 [r=301,l]//define rewrite rules, this rule does not execute when the above conditions are met </IfModule>
</VirtualHost>
Vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf
/usr/local/apache2/bin/apachectl-m |grep Rewrite//If no module is required, edit the configuration file httpd.conf, delete the previous # of Rewrite_module (shared)
Check the module again and it's out.
Reload Configuration
Curl-x127.0.0.1:80-i 123.com//Status Code 301 indicates successful setup
Change the granted to denied then the status becomes 403.
Enter a URL randomly to 404, indicating that there is no
Third, Apache access log
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
View logs for 111.com
Cat/usr/local/apache2.4/logs/111.com-access_log
Change the virtual host configuration file to the following:
Vim/usr/local/apache2.4/conf/httpd.conf
Vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf
Switch
<virtualhost *:80>
DocumentRoot "/data/wwwroot/www.111.com"
ServerName www.111.com
Serveralias 111.com
Customlog "Logs/111.com-access_log" combined
</VirtualHost>
Reload the configuration file-t,graceful
Curl-x127.0.0.1:80-i 111.com
Tail/usr/local/apache2.4/logs/111.com-access_log
Linux CentOS7 VMware lamp architecture Apache user authentication, domain jump, Apache access log