Apache user authentication, domain jump, Apache access log

Source: Internet
Author: User
Tags curl apache access log

11.18 Apache user authentication
    • Edit httpd-vhosts.conf configuration file

[[email protected] ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf #内容参数如下:<VirtualHost *:80>    DocumentRoot "/data/wwwroot/123.com"    ServerName 123.com    <Directory /data/wwwroot/123.com>        AllowOverride AuthConfig        AuthName "123.com user auth"        AuthType Basic        AuthUserfile /data/.htpasswd        require valid-user    </Directory>    ServerAlias www.123.com    ErrorLog "logs/123.com-error_log"    CustomLog "logs/123.com-access_log" common</VirtualHost>#含义说明    <Directory /data/wwwroot/123.com>  #指定认证的目录        AllowQverride AuthConfig  #这个相当于打开认证的开关        AuthName "123.com user auth"  #自定义认证的名字,作用不大        AuthType Basic  #认证 的类型,一般为Basic        AuthUserFile /data/.htpasswd  #指定密码文件所在位置        require valid-user  #指定需要认证的用户为全部可用用户
    • Password generator

[[email protected] ~]# /usr/local/apache2.4/bin/htpasswd -cm /data/.htpasswd ayun# -c 表示创建  -m 指定MD5加密 指定所在位置  如果再次增加用户可以不用-c选项,-c是首次创建文件使用的[[email protected] ~]# cat /data/.htpasswdayun:$apr1$0bRU1d91$qRqDfW4bvxeHhShhtSCKs1
    • HTPASSWD Command Introduction
      The HTPASSWD command is an Apache Web server built-in tool for creating and updating password files that store user names, domains, and user Basic authentication.
      Syntax: htpasswd [option] [parameter]
      Options:
      -c:=create, create an encrypted file
      -N: Do not update encrypted files, only the updated user name password is displayed on the screen
      -M: Encrypt the password using the MD5 algorithm (default)
      -D: Encrypt passwords using the crypt algorithm
      -P: Password is not encrypted, that is, the plaintext password
      -S: Encrypt passwords using the SHA algorithm
      -B: Enter the user name and password at the command line instead of the password as prompted
      -D: Delete the specified user

    • -T && Graceful

[[email protected] ~]# /usr/local/apache2.4/bin/apachectl -tSyntax OK[[email protected] ~]# /usr/local/apache2.4/bin/apachectl graceful

    • Browser testing

    • Curl Test

[[email protected] ~]# curl -x127.0.0.1:80 www.123.com -IHTTP/1.1 401 Unauthorized #状态码401Date: Thu, 21 Dec 2017 02:49:11 GMTServer: Apache/2.4.28 (Unix) PHP/7.1.6WWW-Authenticate: Basic realm="123.com user auth"Content-Type: text/html; charset=iso-8859-1#此时提示状态码为“401”,说明当前所访问的内容需要进行用户认证。# -u 验证用户和密码[[email protected] ~]# curl -x127.0.0.1:80 -uayun:ayunayun www.123.com -IHTTP/1.1 200 OKDate: Thu, 21 Dec 2017 02:50:23 GMTServer: Apache/2.4.28 (Unix) PHP/7.1.6X-Powered-By: PHP/7.1.6Content-Type: text/html; charset=UTF-8#状态码“200”,即访问成功。

Set user authentication for a specified file in a Web site

    • Configuring the Httpd-vhosts.conf File

<VirtualHost *:80>    #ServerAdmin [email protected]    DocumentRoot "/data/wwwroot/123.com"    ServerName 123.com    #<Directory /data/wwwroot/123.com> 注释Directory标签     <FilesMatch 123.php> #改成FilesMatch标签        AllowOverride AuthConfig        AuthName "123.com user auth"        AuthType Basic        AuthUserfile /data/.htpasswd        require valid-user     </FilesMatch>    #</Directory>    ServerAlias www.123.com    ErrorLog "logs/123.com-error_log"    CustomLog "logs/123.com-access_log" common</VirtualHost>#创建123.php文件[[email protected] ~]# echo ‘<?php echo "abc.cm/123.php " ?>‘ > /data/wwwroot/123.com/123.php

    • Detection


Browser access

Note: When accessing 123.php, you need to enter the authentication username & password.

11.19-11.20 Domain Jump
    • 302 Jump is a temporary jump, the search engine will crawl new content and retain the old URL. Because the server returns 302 code, the search engine thinks the new URL is only temporary.
    • 301 redirects are permanent redirects, and search engines also replace old URLs with redirected URLs while crawling new content.
    • SEO (Search engine Optimization) search engine optimization, on the basis of understanding the natural ranking mechanism of the search engine, the site for internal and external adjustment optimization, improve the site in search engine keywords natural ranking, get more traffic, In order to achieve the website sales and brand construction of the expected target.
      Configure a domain name jump

#配置文件[[email protected] ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf #配置参数<VirtualHost *:80>    DocumentRoot "/data/wwwroot/123.com"    ServerName 123.com    <IfModule mod_rewrite.c>        #需要mod_rewrite的支持        RewriteEngine on                #开启rewrite功能        RewriteCond %{HTTP_HOST} !^123.com$                #Cond=condition,定义rewrite条件:所有非123.com的主机名(域名)        RewriteRule ^/(.*)$ http://123.com/$1 [R=301,L]                #定义rewrite规则:当满足上面条件时才执行当前规则,即跳转到111.com。    </IfModule>    ServerAlias www.abc.com    ErrorLog "logs/123.com-error_log"    CustomLog "logs/123.com-access_log" common</VirtualHost>
    • Check

检查系统配置[[email protected] ~]# /usr/local/apache2.4/bin/apachectl -tSyntax OK[[email protected] ~]# /usr/local/apache2.4/bin/apachectl graceful#检查Apache是否加载了配置中调用的rewrite模块,如果没有加载,需要编辑Apache配置文件“httpd.conf”LoadModule alias_module modules/mod_alias.soLoadModule rewrite_module modules/mod_rewrite.so  #注释去掉LoadModule php7_module        modules/libphp7.so查看是否有加载模块[[email protected] ~]# /usr/local/apache2.4/bin/apachectl -M |grep rewrite rewrite_module (shared)

    • Curl Detection

[[email protected] ~]# curl -x127.0.0.1:80 www.abc.com -IHTTP/1.1 301 Moved PermanentlyDate: Thu, 21 Dec 2017 03:46:09 GMTServer: Apache/2.4.28 (Unix) PHP/7.1.6Location: http://123.com/Content-Type: text/html; charset=iso-8859-1

Status code is 301, that is, set the domain name permanent jump

When the browser detects, the access "www.example.com" jumps directly to "123.com".



11.21 Apache Access Log
    • directory where log files are located

[[email protected] ~]# ls /usr/local/apache2.4/logs111.com-access_log  123.com-access_log  access_log  httpd.pid111.com-error_log   123.com-error_log   error_log#查看日志记录[[email protected] ~]# cat /usr/local/apache2.4/logs/abc.com-access_log 192.168.1.222 - - [05/Jan/2018:16:09:39 +0800] "GET /favicon.ico HTTP/1.1" 404 209192.168.1.222 - - [05/Jan/2018:16:09:40 +0800] "GET /.php HTTP/1.1" 404 202192.168.1.222 - - [05/Jan/2018:16:09:47 +0800] "GET /index.html HTTP/1.1" 404 208192.168.1.222 - - [05/Jan/2018:16:09:50 +0800] "GET /index.html HTTP/1.1" 404 208192.168.1.222 - - [05/Jan/2018:16:12:35 +0800] "GET /favicon.ico HTTP/1.1" 404 209192.168.1.222 - - [05/Jan/2018:16:12:35 +0800] "GET /favicon.ico HTTP/1.1" 404 209

    • Custom log Format

#文件路径[[email protected] ~]# vim /usr/local/apache2.4/conf/httpd.conf#参数注解    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined    LogFormat "%h %l %u %t \"%r\" %>s %b" common        #h表示host来源IP        #l表示login用户        #u表示user用户密码        #t表示time时间        #r表示request(行为)        #s表示status状态码        #b表示byte大小#user-agent:用户代理#referer:跳转到当前位置的上一个网址(即:提供当前IP的网站)即:有combine和common两种格式,默认使用common模式

As follows:

    • Configuration log Format

Edit configuration File "Httpd-vhosts.conf"



Reload

[[email protected] ~]# /usr/local/apache2.4/bin/apachectl -tSyntax OK[[email protected] ~]# /usr/local/apache2.4/bin/apachectl graceful
    • Cat/usr/local/apache2.4/logs/123.com-access_log

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.