httpd redirect jumps and more verbose logging

Source: Internet
Author: User

httpd的页面登录认证
To add a user-authenticated password to the HTTPD virtual host configuration file

<VirtualHost *:80> ?  DocumentRoot "/usr/local/httpd/docs/123.com" ?  ServerName 123.com ?  ServerAlias www.123.com ? <directory /usr/local/httpd/docs/123.com> ?  AllowOverride AuthConfig ?  AuthName "Please is passwd :" ?  AuthType Basic ?  AuthUserFile /usr/local/httpd/conf/htpasswd ?  require valid-user ? </Directory> ?  ErrorLog "logs/123.com-error_log" ?  CustomLog "logs/123.com-access_log" common</VirtualHost>

directory specifies the root directory of the Web page that requires authentication, and access to the pages in this directory requires the authentication account name and password to be entered.
allowoverride authconfig account password Authentication in effect configuration, keep this configuration
AuthName the information that is prompted when the account password authentication is entered
AuthType Basic Account password Authentication type, common basic type can be
AUTHUSERFILE/USR/LOCAL/HTTPD/CONF/HTPASSWD Specify the directory of the account password configuration file
Require valid-user specifies that users who need authentication are all available users (users within the profile)

Use the htpasswd file under HTTPd to add the user authentication name and password, the first time you create a password-certified file, you must add the-C option, in order to create a save user and password Authentication file, subsequent new users no longer need to use the-C option

[[email protected] extra]# /usr/local/httpd/bin/htpasswd -c /usr/local/httpd/conf/htpasswd userNew password: Re-type new password: Adding password for user user ? ? ? ? ?[[email protected] extra]# /usr/local/httpd/bin/htpasswd /usr/local/httpd/conf/htpasswd user1New password: Re-type new password: Adding password for user user1[[email protected] extra]# cat /usr/local/httpd/conf/htpasswd user:$apr1$Xh6mrleA$/PHet3mzd4ZKbk7eLTMfH1user1:$apr1$zK/oShKB$Q7.pLsBHEsphBA6HnCl0E/

Reload the httpd configuration
[[email protected] extra]# /usr/local/httpd/bin/apachectl graceful
Access to Domain name verification user authentication Settings results

Domain Jump

httpd set the domain name jump

<VirtualHost *:80> ?  DocumentRoot "/usr/local/httpd/docs/abcd.com" ?  ServerName abcd.com ?  ServerAlias www.abcd.com ?  ErrorLog "logs/abcd.com-error_log" ?  CustomLog "logs/abcd.com-access_log" common ? <IfModule mod_rewrite.c> ?  RewriteEngine on ?  RewriteCond %{HTTP_HOST} !^111.com$ ?  RewriteRule ^/(.*)$ http://111.com/$1 [R=301,L] ? </IfModule></VirtualHost>

Ifmodule mod_rewrite.c? Indicates the need for Mod_rewrite module support
Rewriteengine? Indicates the rewrite function of the final exam
Rewritecond defines the conditions for rewrite jumps
Rewriterule? The rules defined here are executed when the rewrite rule is defined and the Rewritecond condition is met

See if httpd has loaded the rewrite module, and if there is no rewrite module (most of which will be installed on the httpd compile), follow the next step to load rewrite

[[email protected] conf]# /usr/local/httpd/bin/apachectl -M |grep rewrite rewrite_module (shared)

Open the Rewrite module in the httpd configuration file, find the rewrite module, and remove the comment reload httpd configuration file

[[email protected] conf]# vim httpd.conf~LoadModule alias_module modules/mod_alias.soLoadModule rewrite_module modules/mod_rewrite.so[[email protected] conf]# /usr/local/httpd/bin/apachectl graceful

Test the access request for the domain jump, the configuration file is specified in the 301 ID, where the 301 is also represented as the identity of the domain jump

[[email protected] conf]# curl -x127.0.0.1:80 http://www.abcd.com -IHTTP/1.1 301 Moved PermanentlyDate: Sun, 29 Jul 2018 17:48:31 GMTServer: Apache/2.4.33 (Unix) PHP/5.6.37Location: http://111.com/Content-Type: text/html; charset=iso-8859-1
httpd Log

httpd logging, in the main configuration file to find the configuration of the Logformat segment, Logformat here is to let the log in a specific form of record saving, you can customize the log format here

<IfModule log_config_module> ? ?# ? ?# The following directives define some format nicknames for use with ? ?# a CustomLog directive (see below). ? ?# ?  LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined ?  LogFormat "%h %l %u %t \"%r\" %>s %b" common

Referer is a record of click Page request information
USER-AGEBT is information that records the type of Access segment browser

Define a more detailed log of records in a virtual host

[[email protected] httpd]# vim conf/extra/httpd-vhosts.conf -------------------------省略的配置--------------------------------- ?  ErrorLog "logs/123.com-error_log" ?  CustomLog "logs/123.com-access_log" combined ? <---记录模式,更为详细的日志信息</VirtualHost>

Reload httpd The configuration of the active service
[Email protected] httpd]#/usr/local/httpd/bin/apachectl Graceful

Compare the log content recorded before and after the modification, log the type of browser accessed by the client, access the page and the operating system and other information

192.168.1.112 - - [30/Jul/2018:00:56:33 +0800] "GET / HTTP/1.1" 401 381192.168.1.112 - - [30/Jul/2018:00:57:13 +0800] "GET /favicon.ico HTTP/1.1" 401 381192.168.1.112 - - [30/Jul/2018:00:57:13 +0800] "GET /favicon.ico HTTP/1.1" 401 381192.168.1.112 - user [30/Jul/2018:04:39:41 +0800] "GET / HTTP/1.1" 200 7192.168.1.112 - user [30/Jul/2018:04:44:07 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"192.168.1.112 - user [30/Jul/2018:04:44:08 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"192.168.1.112 - user [30/Jul/2018:04:44:09 +0800] "GET / HTTP/1.1" 200 7 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36"

httpd redirect jumps and more verbose logging

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.