Linux Learning Summary (34) Lamp user authentication and domain jump

Source: Internet
Author: User

User authentication

For the security needs of certain websites, specific users are specifically authorized to access, thus creating a user authentication mechanism for website access. We can authenticate against a site, or we can specify a directory, or a file. To edit a virtual host configuration file:
vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf//The 123.com virtual host is edited into the following content

<VirtualHost *:80>    DocumentRoot "/data/wwwroot/www.123.com"    ServerName www.123.com    ServerAlias 123.com    <Directory /data/wwwroot/www.123.com> //指定认证的目录        AllowOverride AuthConfig //这个相当于打开认证的开关        AuthName "123.com user auth" //自定义认证的用户名        AuthType Basic //认证的类型,一般为Basic        AuthUserFile /data/.htpasswd  //指定密码文件所在位置        require valid-user //指定需要认证的用户为全部可用用户    </Directory></VirtualHost>

/usr/local/apache2.4/bin/htpasswd -cm /data/.htpasswd lvSpecify the user, create the password.
Reload config-T, graceful
Binding hosts, browser testing
CURL-X127.0.0.1:80 123.com//Status code 401
Curl-x127.0.0.1:80-lv:lvlinux 123.com//Status Code 200
If you want to do certification for a directory, such as to the www.123.com/admin/directory certification, only need to modify a place to do. Change <Directory/data/wwwroot/www.123.com> to <directory/data/wwwroot/www.123.com/admin/>. If you want to authenticate against a file, use the Filematch feature, which is configured as follows.

<VirtualHost *:80>    DocumentRoot "/data/wwwroot/www.123.com"    ServerName www.123.com    ServerAlias 123.com    <FilesMatch admin.php>        AllowOverride AuthConfig        AuthName "123.com user auth"        AuthType Basic        AuthUserFile /data/.htpasswd         require valid-user    </FilesMatch></VirtualHost>
Domain Jump

We know that we in the Baidu search engine access to a domain name, will be crawler records, a domain name of the greater the number of access, the more easily be searched. For example, there is a site to register the domain name is a, and then we re-start a better domain B, to let B domain name access to the site, we just need to simply give a domain name alias B can be, but so that the crawler will be two domain names, so our traffic by two domain names apportioned, So how do we increase the weight of our a domain in the reptile eye? Then you need to jump the B domain to the a domain. As a result, new users remember a more valuable domain name, and our traffic is concentrated together. Domain name jumps are also called domain redirection.
requirements, the 123.com domain name jump to www.123.com, configured as follows:

<VirtualHost *:80>    DocumentRoot "/data/wwwroot/www.123.com"    ServerName www.123.com    ServerAlias 123.com    <IfModule mod_rewrite.c> //需要mod_rewrite模块支持        RewriteEngine on  //打开rewrite功能        RewriteCond %{HTTP_HOST} !^www.123.com$  //定义rewrite的条件,主机名(域名)不是www.123.com满足条件        

The rewrite configuration above means that we automatically jump to the server domain name when we access it using the alias name. Using Curl to access will see our defined status Code 301, if accessed by the browser will find that the IP will automatically jump.
/usr/local/apache2/bin/apachectl-m|grep-i rewrite//Without this module, you need to edit the configuration file httpd.conf, delete the front of the Rewrite_module (shared) #
Curl-x127.0.0.1:80-i 123.com//Status Code 301

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
The main configuration file provides two kinds of access log format let us choose, where the virtual host is the default is common, we see combined format richer, he is more referer and user-agent, we will edit the virtual host configuration file, Change the common to combined, revisit the test, and view the log.
Change the virtual host configuration file to the following:

 <VirtualHost *:80>    DocumentRoot "/data/wwwroot/www.123.com"    ServerName www.123.com    ServerAlias 123.com    CustomLog "logs/123.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

Linux Learning Summary (34) Lamp user authentication and domain jump

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.