Nginx configuration and access control

[TOC]

Article Directory

A, Nginx Profile

A high-performance, lightweight Web services software, high stability, low system resources consumption, high processing power of concurrent HTTP connections

Two, Nginx configuration

2.1, the installation and decompression dependencies

2.2, compile and install configuration

2.3, Production Manager script

Modify 2.4, nginx.conf file

2.5, configure the DNS domain name resolution

Third, access control

3.1, based on the authorization of access control

3.2, a client-based access control

A, Nginx Profile

A high-performance, lightweight Web services software, high stability, low system resources consumption, high processing power of concurrent HTTP connections

Two, Nginx configuration

You need to prepare the installation package:

Can be remotely mounted by first compressed manner from a Windows system, mounted to linux system, then after the compression operation.

2.1, the installation and decompression dependencies

In an IP address is 192.168.111.141 in system centos7

1, the installation dependencies

Nginx configuration and access control

2, create a user named nginx, and not allowed to log into the system

Nginx configuration and access control

3, mount, and extract the installation package to the specified / opt / in

Nginx configuration and access control

2.2, compile and install configuration

1, the compiler configuration

Nginx configuration and access control

2, make the compiler

Nginx configuration and access control

3, turn off the firewall, optimal path

Nginx configuration and access control
4. Check for error

Nginx configuration and access control

5, loading the installation package elinks, elinks test with

Nginx configuration and access control

nginx -t // check

nginx // start

killall -1 nginx // reload

killall -3 nginx // stop

Nginx configuration and access control

Nginx configuration and access control

Nginx configuration and access control

2.3, Production Manager script

1, Production Manager script to control the open and close of Nginx.

Nginx configuration and access control

Nginx configuration and access control

Nginx configuration and access control

2, add execute permissions, add the script to the list of services

Nginx configuration and access control

Modify 2.4, nginx.conf file

In the main configuration file /usr/local/nginx/conf/nginx.conf Nginx server, including global configuration, I / O event configuration, HTTP configuration three large content.

Nginx configuration and access control

1, the global configuration

Nginx configuration and access control

2, I / O Event Configuration

Nginx configuration and access control

3, HTTP Configuration

Nginx configuration and access control

Nginx configuration and access control

Access to state statistics

nginx built HTTP_STUB_STATUS state statistics module, used to feed the current situation of Web access, you can add --with-http_stub_status_module compile time configuration parameters to enable this module supports.

Can use the command: / usr / local / nginx / sbin / nginx -V to view the installed Nginx contains HTTP_STUB_STATUS module.

To use Nginx state statistical functions, in addition to the built-enabled module, nginx.conf also you need to modify the configuration file, specify the location and add stub_status access configuration code.

Only modified region server {} nginx.conf profile:

Nginx configuration and access control

After modifying the configuration files, you can restart the service.

Nginx configuration and access control

2.5, configure the DNS domain name resolution

1, the installation

Nginx configuration and access control

2, modify

Nginx configuration and access control

Nginx configuration and access control

Nginx configuration and access control

Nginx configuration and access control

Nginx configuration and access control

3, start the service named

Nginx configuration and access control

In a client system win10

Modify the DNS server address

Nginx configuration and access control

Nginx configuration and access control

Enter www.king.com/status in win10 browser.

Nginx configuration and access control

Nginx configuration and access control

Third, access control

3.1, based on the authorization of access control

Nginx and Apache, like, can be achieved based access control for authorization, when the client wants to access the site will be asked to enter a user name and password before you can access, and Apache configuration steps are basically the same.

Based authorization access control configuration roadmap:

Generate user-password authentication file

Modifying the master configuration file to the appropriate directory, add authentication configuration items

Restart the service, access the test

1, the main configuration file nginx.conf modify, add the appropriate authentication configuration items.

Nginx configuration and access control

Nginx configuration and access control

Installation tools package

Nginx configuration and access control

htpasswd command generates user authentication file

Nginx configuration and access control

Nginx configuration and access control

3, modify the configuration file, you must restart the service

Nginx configuration and access control

4, this time using a browser to access the web site win10 www.king.com, will be asked to enter a user name and password wanglu 123123

Nginx configuration and access control

3.2, a client-based access control

By the client's IP address to determine whether to allow access to the page, the following rules:

deny ip / ip segment: ip or deny an IP segment access;

allow ip / ip segment: ip or allow certain IP segment access;

Rules: from the top down, as the match is stopped and no longer match down

My win10 host IP address is 192.168.111.140

Configuration process:

1, the main configuration file nginx.conf modify, add the appropriate authentication configuration items.

Nginx configuration and access control

Nginx configuration and access control

2, modify the configuration file, you must restart the service

Nginx configuration and access control

3, in the authentication system win10:

Nginx configuration and access control

Guess you like

Origin blog.51cto.com/14557584/2461720