Nginx,apache's alias and authentication function _nginx

Source: Internet
Author: User
Tags auth crypt parent directory require phpmyadmin
Since the computer switched to Linux from a year ago did not write things, recently a bit lazy, here to tell the next Nginx alias function, not server alias.
First look at how the Apache alias is configured:

Copy Code code as follows:

<virtualhost *:80>
Documentroot/www/jb51.net/www This is the root directory of the virtual host, but phpMyAdmin is not in this directory, want to access.
ServerName www.jb51.net
Serveralias jb51.net
Alias/sdb "/www/public/phpmyadmin/" requires an alias function: Http://www.jb51.net/sdb is much safer.
<directory "/www/public/phpmyadmin/" >
Options Indexes FollowSymLinks
AllowOverride None
Order Allow,deny
Allow from all
</Directory>
</VirtualHost>


one. Apache Authentication

Type of authentication: Basic
Digest Summary
Authentication methods: A, container certification: ...
B, hidden file authentication create. htaccess file
Method one, container authentication
A, enter the configuration file vi/etc/httpd/conf/httpd.conf
B, configuration: Approximately 531 lines near the following configuration:

AllowOverride None # #不允许通过隐藏认证, that is, through the container certification
AuthType Basic # # Authentication type is basic
AuthName "Ajian" # # Certification name is Ajian
Authuserfile/var/www/passwd/pass ##pass for the authentication password file, specify the location where the password file is stored.
Require Valid-user # # Valid Users (note case, because Word causes some changes in capitalization)
C, create a directory mkdir-p/var/www/passwd
Enter Directory CD/VAR/WWW/PASSWD
D, create Apache user htpasswd-c pass Ajian # #pass for password file Ajian for user
Change the use of the pass file to Apache:chown Apache.apache Pass
Attach: Then add a user to the pass file: htpasswd Pass TT # #添加一个TT的用户到Pass文件中
E, restart the service and test
Methods two, through the hidden authentication
Similar to the top, but not the same.
HTTPD Master configuration file

AllowOverride authconfig
Create hidden files and place them in a 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

Second, Nginx login certification

The password for the Nginx HTTP auth Basic is encrypted with crypt (3). Use Apache htpasswd to generate a password file.
No Apache installs itself. I installed the APACHE2,/USR/LOCAL/APACH2.
Cd/usr/local/nginx/conf/usr/local/apache2/bin/htpasswd-c-D pass_file user_name #回车输入密码,-C means the makefile,-D is encrypted with crypt.
VI nginx.conf cd/usr/local/nginx/conf/usr/local/apache2/bin/htpasswd-c-D pass_file user_name #回车输入密码,-C indicates the makefile,-D is in C Rypt encryption. VI nginx.conf to add an authorization statement in the nginx.conf file. Notice here that Nginx 0.6.7 begins, Auth_basic_user_file's relative directory is nginx_home/conf, and the previous version of the relative directory is nginx_home.

Copy Code code 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, the PHP file is not executed and will be downloaded in a separate location and nested in the location to explain PHP location. Auth_basic after the nested location.
Copy Code code 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;
}


three. Nginx alias feature configures automatic column directory

Copy Code code as follows:

server {

Listen www.jb51.net:88;

server_name www.jb51.net;

AutoIndex on; Opens the Column directory feature.

# charset GBK;
Location/club {The name of the visit http://www.jb51.net:88/club
alias/www/clublog/club.xywy.com/; This is where the logs are stored on the server.
The meaning of the visit Www.jb51.net:88/club to see the club directory of Dongdong.
Location/{
root/www/access;
This section of location can also not www.jb51.net:88 out of the default nxing page
# index index.html index.htm index.php;
}
Error_page 502 503 504/50x.html;
Location =/50x.html {
root HTML;
}
}


The above Nginx configuration means: Access to http://hou.xywy.com/:88 authentication is the default access to the server/www/access/inside the directory, certification into the Url=http://hou.xywy.com:88/club came out/ The contents of the catalogue inside the www/clublog/club.xywy.com/. , it may be a round, careful analysis of the good.

The difference between Root and alias.
The most basic difference: alias Specifies that the directory is accurate, root is the parent directory of the specified directory, and the parent directory contains a directory with the same name as the location specified. In addition, rewrite break can not be used in a directory block that uses an alias label, as described earlier in this article.

So it's clear to see the paragraph,
Copy Code code as follows:

location/abc/{
alias/home/html/abc/;
}

In this configuration, the http://test/abc/a.html specifies the/home/html/abc/a.html. This configuration can also be changed into
Copy Code code as follows:

location/abc/{
root/home/html/;
}

In this way, Nginx will find the/home/html/directory under the ABC directory, the results are the same.

However, if I change the alias configuration to:
Copy Code code as follows:

location/abc/{
alias/home/html/def/;
}

Then Nginx will take the data from the/home/html/def/, this configuration can not directly use the root configuration, if you want to configure, only under the/home/html/to create a def->abc soft link (shortcut).

In general, configuring root in Location/is a good habit of configuring alias in Location/other.

As for the difference between the alias and root, I guess I haven't said it yet, but if you find a singular problem when you configure it, you might as well change the two for a try.

At first I got high and had a long time. Including authentication of a single directory CGI problem, I hope everyone succeeds. There are problems can be consulted to me for common progress!

This article comes from the "learning to be eternal" blog

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.