HTTPD user authentication, user authentication of individual files, domain jump, record access log

Source: Internet
Author: User
Tags php error

For httpd users plus authentication

Modify the 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
<Directory/data/wwwroot/www.123.com>//Designation of certified directories
AllowOverride authconfig//This equivalent to open the authentication switch
AuthName "123.com user auth"//Custom certified name, not very useful
AuthType Basic//authentication type, generally basic, other types of Amin useless
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>

* * * add aming User and configure password, this place is difficult, * *
[[email protected] ~]#/usr/local/ Apache2.4/bin/htpasswd-c-m/data/.htpasswd aming
New password:
re-type new password:
Adding password for user Aming
[[email protected] ~]# cat/data/.htpasswd
aming: $apr 1$ddmcbmzv$zgobr361t5hlhmsdewyf2/
[[ Email protected] ~]#/usr/local/apache2.4/bin/htpasswd-m/data/.htpasswd zhangsan
New Password:
Re-type New password:
Adding password for user Zhangsan
Reload configuration-t,graceful
[[email protected] wwwroot]#/usr/ Local/apache2.4/bin/apachectl-t
Syntax OK
[[email protected] wwwroot]#/usr/local/apache2.4/bin/ Apachectl Graceful

[Email protected] wwwroot]# curl-x127.0.0.1:80 111.com
<! DOCTYPE HTML PUBLIC "-//ietf//dtd HTML 2.0//en" >
<title>401 unauthorized</title>
<p>this Server could not verify
is authorized to access the document
Requested. Either you supplied the wrong
credentials (e.g., bad password), or your
Browser doesn ' t understand how to supply
The Credentials required.</p>
</body>[Email protected] wwwroot]# curl-x127.0.0.1:80 111.com-i
http/1.1 401 Unauthorized
Date:sun, Mar 2018 09:01:00 GMT
Server:apache/2.4.29 (Unix) php/7.1.6
Www-authenticate:basic realm= "111.com user auth"
content-type:text/html; Charset=iso-8859-1

Adding native IP 111.com to the native host file
Browser attempt, prompt for user name password, display content

If you add the-u parameter Test at the command line, you can also succeed with the user name: password.
[Email protected] wwwroot]# curl-x127.0.0.1:80-uaming:1q2w3e 111.com-i
http/1.1 OK
Date:sun, Mar 2018 09:04:54 GMT
Server:apache/2.4.29 (Unix) php/7.1.6
x-powered-by:php/7.1.6
content-type:text/html; Charset=utf-8

Certification for individual files
Edit a virtual host configuration file
[Email protected] ~]# vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf


Restart Service
[Email protected] ~]#/usr/local/apache2.4/bin/apachectl-t
Syntax OK
[Email protected] ~]#/usr/local/apache2.4/bin/apachectl Graceful

Add 123.php files and edit

command line access to the 1111.com host succeeded, Access 111.com/123.php error.
[Email protected] ~]# curl-x192.168.67.128:80 111.com/123.php
<! DOCTYPE HTML PUBLIC "-//ietf//dtd HTML 2.0//en" >
<title>401 unauthorized</title>
<p>this Server could not verify
is authorized to access the document
Requested. Either you supplied the wrong
credentials (e.g., bad password), or your
Browser doesn ' t understand how to supply
The Credentials required.</p>
</body>

At this point, you can add a user name and password for this file.

[Email protected] ~]# curl-x127.0.0.1:80-uaming:1q2w3e 111.com/123.php-i
http/1.1 OK
Date:sun, Mar 2018 09:26:59 GMT
Server:apache/2.4.29 (Unix) php/7.1.6
x-powered-by:php/7.1.6
content-type:text/html; Charset=utf-8
Login Web page validation succeeded.

I tried again. If the addition is not the root user, is not a system user, just for httpd users, add a K user, and set the password, you can also access 123.php files.

Domain Jump * * *

Vim/usr/local/apache2.4/conf/extra/httpd-vhosts.conf

Rewriterule ^/(.) $ http://111.com/$1 [r=301,l]
$ $ represents the contents of the first parenthesis above,
If you have a second parenthesis in front, you should add the following
Like what
Rewriterule ^/(.
) ("1-9" +) $ http://111.com/$1 $2[r=301,l]

Define status code, R=301, L represents only one jump, last
r=301 means Permanent
r=302 indicates temporary effect, does not reduce the original domain weight

Reload

Check if the rewrite module is loaded

检查模块是否加载到vi /usr/local/apache2.4/conf/httpd.conf

Reload to see if it loads into

Modify the virtual host configuration file, add the domain name 2111.com.cn restart, take effect

Start test domain jump

Show 301 Jump Success

403 no authorization or incorrect username and password
200 User name password is correct
Access 2111.com.cn/123.php via Web test, jump to

Logging access logs

Editing a configuration file
vim/usr/local/apache2.4/conf/httpd.conf//Search Logformat
Modify the logging format

Reload config file-T, graceful
To start the test:
1, check the log file, not jump over the same connection as before.
2, create a blog in 51 blog creates a new link, in the blog to open the link, in the log can see the new log file

HTTPD user authentication, user authentication of individual files, domain jump, record 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.