Apache user authentication, domain name redirection, Apache access log

Apache user authentication:

 vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf //Edit the virtual host of 123.com to the following content
<VirtualHost *:80>
    DocumentRoot "/data/wwwroot/www.123.com "
    ServerName www.123.com
    <Directory /data/wwwroot/www.123.com> //Specify the directory for authentication
        AllowOverride AuthConfig //This is equivalent to opening the authentication switch
        AuthName "123.com user auth" //Custom authentication
        AuthType Basic //The type of authentication, generally Basic, other types A Ming has never used AuthUserFile /data/.htpasswd
        //Specify the location of the password file
        require valid-user //Specify the user to be authenticated as All available users
    </Directory>

</VirtualHost>
 /usr/local/apache2.4/bin/htpasswd -c -m /data/.htpasswd aming 
 reload configuration

/usr/local/apache2.4/bin/apachectl -t , = test configuration file is correct

/usr/local/apache2.4/bin/apachectl graceful = reload
 the configuration file binding hosts (Windows hosts file), browser test
 curl -x127.0.0.1:80 www.123.com //The status code is 401 indicates that the user and password need to be authenticated
 curl -x127.0.0.1:80 -uaming:passwd www.123.com //The status code is 200 for correct authentication 200=no problem

The configuration file is modified as follows:

After the configuration file is modified, generate a password:

 /usr/local/apache2.4/bin/htpasswd -c -m /data/.htpasswd aming (test machine password rabbit)

The second time to create a new user again then -c is not needed because the password file has already been created.

 

 

 

Domain jump:

Domain name jump classification and difference

type:

301 represents a permanent jump; 302 represents a temporary jump.

the difference:

  • Different effects
    • 302 redirects are temporary redirects, search engines will crawl new content and keep old URLs. Because the server returns a 302 code, the search engine considers the new URL to be temporary.
    • A 301 redirect is a permanent redirect where search engines crawl new content and replace the old URL with the redirected URL.
  • Different ways of using SEO
    In search engine optimization, 302 jumps are pursued by many black hat SEO optimization personnel, and malicious 302 jumps to websites are redirected to non-user target sites. Therefore, search engines are usually unfriendly to 302 jumps of websites. So use 302 jump with caution!

SEO

SEO (Search Engine Optimization) Search engine optimization, on the basis of understanding the natural ranking mechanism of search engines, adjusts and optimizes the website internally and externally, improves the natural ranking of keywords in the search engine, and obtains more traffic, so as to achieve Expected goals for website sales and brand building.

 

Domain Jump Configuration

  • Configure the virtual host configuration file: httpd-vhosts.conf.
[root@adailinux ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
……
<VirtualHost *:80>
    DocumentRoot "/data/wwwroot/111.com"
    ServerName 111.com
    ServerAlias www.example.com
    <IfModule mod_rewrite.c>
    #需要mod_rewrite的支持
        RewriteEngine on
        #开启rewrite功能
        RewriteCond %{HTTP_HOST} !^111.com$
        #Cond=condition,定义rewrite条件:所有非111.com的主机名(域名)
        RewriteRule ^/(.*)$ http://111.com/$1 [R=301,L]
        #定义rewrite规则:当满足上面条件时才执行当前规则,即跳转到111.com。
    </IfModule>
    ErrorLog "logs/111.com-error_log"
    CustomLog "logs/111.com-access_log" common
</VirtualHost>
<IfModule mod_rewrite.c> //需要mod_rewrite模块支持
        RewriteEngine on  //打开rewrite功能    on=打开  off=关闭
        RewriteCond %{HTTP_HOST} !^111.com$  //定义rewrite的条件,主机名(域名)不是www.123.com满足条件     =  当域名不是  111.com  那么就会进行跳转
        RewriteRule ^/(.*)$ http://111.com/$1 [R=301,L] //定义rewrite规则,当满足上面的条件时,这条规则才会执行      R=301 表示永久跳转   L=只跳转一次    R=302 表示临时跳转
</IfModule>
  • Check system configuration:
[root@aminglinux ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@aminglinux ~]# /usr/local/apache2.4/bin/apachectl graceful
[root@aminglinux ~]# /usr/local/apache2.4/bin/apachectl -M |grep rewrite

Check here whether Apache has loaded the rewrite module called in the virtual host configuration, if not, you need to edit the Apache configuration file "httpd.conf" and search for rewrite:

[root@aminglinux ~]# vim /usr/local/apache2.4/conf/httpd.conf   
……
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module        modules/libphp5.so
#LoadModule php7_module        modules/libphp7.so

That is, remove the comment symbol "#" and load the rewrite module.

  • detect
[root@aming-01 ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@aming-01 ~]# /usr/local/apache2.4/bin/apachectl graceful
[root@aming-01 ~]# /usr/local/apache2.4/bin/apachectl -M | grep rewrite
 rewrite_module (shared)

Use curl to detect:

At this time, the status code is 301, that is, the domain name is permanently redirected! Status code 404 means that the page does not exist, and status code 401 means that web page verification is required.

When the browser detects, visiting "www.example.com" will directly jump to "111.com".

 

11.21 Apache access log:

Log file location:

access_log means access log error_log means error log

[root@aminglinux ~]# ls /usr/local/apache2.4/logs
111.com-access_log  abc.com-access_log  access_log  httpd.pid
111.com-error_log   abc.com-error_log   error_log

 

Custom log format

The system comes with log format:

vim /usr/local/apache2.4/conf/httpd.con

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common     common=系统默认格式
#h表示host来源IP,l表示login用户,u表示user用户密码,t表示time时间,r表示request(行为),s表示status状态码,b表示byte大小
#user-agent:用户代理
#referer:跳转到当前位置的上一个网址(即:提供当前IP的网站)

Configure log format

Edit the virtual host configuration file "httpd-vhosts.conf":

[root@aminglinux ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
    DocumentRoot "/data/wwwroot/111.com"
    ServerName 111.com
    ServerAlias www.example.com
    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{HTTP_HOST} !^111.com$
        RewriteRule ^/(.*)$ http://111.com/$1 [R=301,L]
    </IfModule>
    ErrorLog "logs/111.com-error_log"
    CustomLog "logs/111.com-access_log" combined
</VirtualHost>

Description:  Change the original common at the back of the log file to combined.

Reload:

[root@aminglinux ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@aminglinux ~]# /usr/local/apache2.4/bin/apachectl graceful

Check out the changed log style:

[root@aminglinux ~]# cat /usr/local/apache2.4/logs/111.com-access_log

 

 

Extend 
apache virtual host to open short tags for php  http://ask.apelearn.com/question/5370

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325194143&siteId=291194637