Nginx Advanced Configuration (1)--Add user authentication for a virtual host

Source: Internet
Author: User

Version: centos6.5; mysql-5.6.26, nginx-1.6.3;p hp-5.4.37

Environment Architecture: LNMP

1. Configure a second virtual host

You can add a line to the nginx.conf

Include vhosts/*.conf;

This allows us to create a virtual host configuration file under the/usr/local/nginx/conf/vhosts directory.

#mkdir/usr/local/nginx/conf/vhosts

#cd!$

#vim 111.conf//Join

Server


Server

{

Listen 80;

server_name 192.168.137.100;

Index index.html index.htm index.php;

root/data/www;

Location ~. *admin\.php$ {

Auth_basic "Xiayun auth";

AUTH_BASIC_USER_FILE/USR/LOCAL/NGINX/CONF/HTPASSWD;

Include Fastcgi_params;

Fastcgi_pass Unix:/tmp/www.sock;

Fastcgi_index index.php;

Fastcgi_param Script_filename/data/www$fastcgi_script_name;


}

Location ~ \.php$ {

Include Fastcgi_params;

Fastcgi_pass Unix:/tmp/www.sock;

Fastcgi_index index.php;

Fastcgi_param Script_filename/data/www$fastcgi_script_name;

}


}

2. User authentication

You need to install Apache first, you can install it using yum install httpd

Generate a password file, create a user

Htpasswd-c/USR/LOCAL/NGINX/CONF/HTPASSWD Test

Add the test user, the first time you add the-c parameter, the second time add does not need the-c parameter

Summary: User authentication can enable users to log in to a path when user authentication, improve the density

This article from the "10707334" blog, reproduced please contact the author!

Nginx Advanced Configuration (1)--Add user authentication for a virtual host

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.