In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the nginx,apache alias and authentication function case analysis related knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this nginx,apache alias and authentication function example analysis article will have a harvest, let's take a look.
First, take a look at how to configure apache aliases:
The copy code is as follows:
Documentroot / www/jb51.net/www this is the root directory of the virtual host, but phpmyadmin is not in this directory. I want to access it.
Servername www.jb51.net
Serveralias jb51.net
Alias / sdb "/ www/public/phpmyadmin/" requires alias functionality, and: / / www.jb51.net/sdb is much more secure.
Options indexes followsymlinks
Allowoverride none
Order allow,deny
Allow from all
I. Apache certification
Type of certification: basic
Digest Summary
Authentication method: a, container authentication:.
B. Hide file authentication to create .htaccess file
Method 1. Container authentication
A. Enter the configuration file vi / etc/httpd/conf/httpd.conf
B. Configuration: the configuration near line 531 is as follows:
Allowoverride none # # does not allow hidden authentication, that is, container authentication
Authtype basic # # Authentication type is basic
Authname "ajian" # # the certified name is ajian
Authuserfile / var/www/passwd/pass # # pass is an authentication password file that specifies the location where the password file is stored.
Require valid-user # # valid users (pay attention to case, there are some case changes due to word)
C. Create the directory mkdir-p / var/www/passwd
Enter the directory cd / var/www/passwd
D. Create apache user htpasswd-c pass ajian # # pass as password file ajian as user
Change the right to use the pass file to apache: chown apache.apache pass
Attachment: add a user to the pass file: htpasswd pass tt # # add a tt user to the pass file
E. Restart the service and test
Method 2. Through hidden authentication
It's about the same as above, but the configuration is different.
Httpd main configuration file
Allowoverride authconfig
Create hidden files and place them in the directory to be authenticated
Eg: vi / var/www/html/mrtg
Authtype basic
Authname "ajian"
Authuserfile / var/www/passwd/pass
Require valid-user
Here is an example
II. Nginx login authentication
The password for nginx's http auth basic is encrypted with crypt (3). Password files can be generated using apache's htpasswd.
There is no apache to install itself. I installed apache2,/usr/local/apach2.
Cd / usr/local/nginx/conf / usr/local/apache2/bin/htpasswd-c-d pass_file user_name # enter the password,-c means to generate the file, and-d is encrypted with crypt.
Vi nginx.conf cd / usr/local/nginx/conf / usr/local/apache2/bin/htpasswd-c-d pass_file user_name # enter the password,-c means to generate the file, and-d is encrypted with crypt. Vi nginx.conf adds an authorization declaration to the nginx.conf file. Note here that starting with nginx 0.6.7, the relative directory of auth_basic_user_file is nginx_home/conf, and the relative directory of previous versions is nginx_home.
The copy code is as follows:
Server {
Listen 80
Server_name tuan.xywy.com
Root / www/tuangou
Index index.html index.htm index.php
Autoindex on
Auth_basic "input you user name and password"
Auth_basic_user_file htpasswd.file
Location ~ .php ${
Fastcgi_pass 127.0.0.1:9000
Fastcgi_index index.php
Fastcgi_param script_filename / www/tuangou$fastcgi_script_name
Include fastcgi_params
}
Error_page 404 / 404.php
Error_page 403 / 404.php
Access_log / logs/tuan_access.log main
}
For directory authentication, be in a separate location and nest a location that interprets the php in that location, otherwise the php file will not be executed and will be downloaded. Auth_basic comes after a nested location.
The copy code is as follows:
Server {
Listen 80
Server_name tuan.xywy.com
Root / www/tuangou
Index index.html index.htm index.php
Autoindex on
Location ~ ^ / admin/.* {
Location ~\ .php$ {
Fastcgi_pass 127.0.0.1:9000
Fastcgi_index index.php
Fastcgi_param script_filename / www/tuangou$fastcgi_script_name
Include fastcgi_params
}
Root / www/tuangou/
Auth_basic "auth"
Auth_basic_user_file htpasswd.file
}
Location ~ .php ${
Fastcgi_pass 127.0.0.1:9000
Fastcgi_index index.php
Include fastcgi_params
}
Access_log / logs/tuan_access.log main
}
III. Nginx alias function configuration automatic column directory
The copy code is as follows:
Server {
Listen www.jb51.net:88
Server_name www.jb51.net
Autoindex on; / / enables the column directory function.
# charset gbk
Location / club {name of the visit / / www.jb51.net:88/club
Alias / www/clublog/club.xywy.com/; this is where the logs are stored on the server
If you visit www.jb51.net:88/club, you will see something in the club directory.
Location / {
Root / www/access
This location can also be without www.jb51.net:88. What comes out is the default nxing page.
# index index.html index.htm index.php
}
Error_page 500 502 503 504 / 50x.html
Location = / 50x.html {
Root html
}
}
The above nginx configuration means: to access http://hou.xywy.com/:88 authentication is to access the directory in / www/access/ on the server by default, and after authentication, url= http://hou.xywy.com:88/club will come out of the directory in / www/clublog/club.xywy.com/. It may be very roundabout, just analyze it carefully.
The difference between root and alias.
The most basic difference: the directory specified by alias is accurate, root is the parent directory of the specified directory, and the parent directory should contain a directory with the same name as the name specified by location. In addition, as mentioned earlier, rewrite's break cannot be used in directory blocks that use alias tags.
In this way, it will be very clear when you look at this part.
The copy code is as follows:
Location / abc/ {
Alias / home/html/abc/
}
In this configuration, http://test/abc/a.html specifies / home/html/abc/a.html. This configuration can also be changed to
The copy code is as follows:
Location / abc/ {
Root / home/html/
}
In this way, nginx will go to the abc directory in the / home/html/ directory and get the same result.
However, if I change the configuration of alias to:
The copy code is as follows:
Location / abc/ {
Alias / home/html/def/
}
Then nginx will fetch data from / home/html/def/, and this configuration cannot be configured directly with root. If you have to configure it, you have to establish a soft link (shortcut) of def- > abc under / home/html/.
In general, it is a good habit to configure root in location / and alias in location / other.
This is the end of the article on "alias and Authentication function example Analysis of nginx,apache". Thank you for reading! I believe you all have a certain understanding of the knowledge of "alias and certification function example analysis of nginx,apache". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.