Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx website Services-basic Services and access Control

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Brief introduction of Nginx

Nginx is a high-performance, lightweight web service software with high stability, low system resource consumption and high processing capacity for HTTP concurrent connections (a single physical server can support 30000 to 50000 concurrent requests).

Nginx common commands nginx-t check configuration file syntax nginx start nginx service killall-3 nginx stop nginx service killall-s QUIT nginx stop nginx service killall-s HUP nginx reload nginx service killall-1 nginx reload nginx service lab environment

1. Basic source package (no password): https://pan.baidu.com/s/14WvcmNMC6CFX1SnjHxE7JQ

2.CentOS version 7 Linux virtual machine

Experimental procedure

Step 1: remotely obtain the source code package on Windows and mount it to Linux

[root@localhost] # smbclient-L / / 192.168.235.1Enter SAMBA\ root's password: Sharename Type Comment- LNMP Disk [root@localhost ~] # mkdir / abc [root@localhost ~] # mount.cifs / / 192.168.235.1/LNMP / abcPassword for root@//192.168.235.1/LNMP: [root @ localhost ~] # ls / abcDiscuz_X3.4_SC_UTF8.zip nginx-1.12.0.tar.gz php-7.1.10.tar.bz2mysql-boost-5.7.20.tar.gz nginx-1.12.2.tar.gz php-7.1.20.tar.gz

Step 2: decompress the source package

[root@localhost ~] # cd / abc [root@localhost abc] # tar zxvf nginx-1.12.0.tar.gz-C / opt [root@localhost abc] # ls / optnginx-1.12.0 rh

Step 3: download and install the compiler package

[root@localhost abc] # cd / opt [root@localhost opt] # yum install-y\ > gcc\ / / C language > gcc-c++\ / / C++ language > pcre-devel\ / / pcre language tool > zlib-devel / / compressed function Library

Step 4: create program users and configure Nginx service-related components

[root@localhost opt] # useradd-M-s / sbin/nologin nginx// Creator user nginx And limit its non-login terminal [root@localhost opt] # cd nginx-1.12.0/ [root@localhost nginx-1.12.0] #. / configure\ / configure nginx >-- prefix=//usr/local/nginx\ / / specify installation path >-- user=nginx\ / / specify user name >-- group=nginx\ / / specify the group to which the user belongs >-- with- Http_stub_status_module// installation status Statistics Module

Step 5: compile and install Nginx

[root@localhost nginx-1.12.0] # make & & make install

Step 6: optimize the Nginx service startup script and establish a command soft connection

[root@localhost nginx-1.12.0] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ create nginx service command soft link to system command [root@localhost nginx-1.12.0] # systemctl stop firewalld.service / / turn off firewall [root@localhost nginx-1.12.0] # setenforce 0bat / turn off enhanced security function [root@localhost nginx-1.12.0] # nginx/ / input Nginx enables the service [root@localhost nginx-1.12.0] # netstat-ntap | grep 80 / / View port 80 of the service Shows that tcp 0 0 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 01. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. master * LISTEN 7520/nginx:

Step 7: use a browser to visit 192.168.235.158 to access the home page of the Nginx service

Step 8: create a service management script

[root@localhost nginx-1.12.0] # cd / etc/init.d/// cut into the startup configuration file directory #! / bin/bash# chkconfig:-99 20 # # comment information # description: Nginx Service Control ScriptPROG= "/ usr/local/nginx/sbin/nginx" # # set the variable to the nginx command file PIDF= "/ usr/local/nginx/logs/nginx. Pid "# # set variable PID file process number is 5346case" $1 "in start) $PROG # # enable the service ; stop) kill-s QUIT $(cat $PIDF) # # disable the service;; restart) # # restart the service $0 stop $0 start Reload) # # reload service kill-s HUP $(cat $PIDF) *) # # incorrect input prompt echo "Usage: $0 {start | stop | restart | reload}" exit 1esacexit 0 [root@localhost init.d] # chmod + x nginx / / Grant nginx execution permission [root@localhost init.d] # chkconfig-- add nginx / / add nginx to service Manager [ Root@localhost init.d] # service nginx stop / / use service to control nginx service stop [root@localhost init.d] # service nginx start// use service to control access status statistics of Nginx started by nginx service

Enable the HTTP STUB _ STATUS status statistics module

Add-- with-http_ stub status module when ● configures compilation parameters

(we have installed the statistics module by the way.)

● nginx-V to see if the installed Nginx contains the HTTP STUB_ _ STATUS module

Step 1: modify Nginx.conf configuration file [root@localhost ~] # vim / usr/local/nginx/conf/nginx.conf// edit Nginx.conf configuration file 35 server {36 listen 80; 37 server_name www.bdqn.com;// specify the domain name 39 charset utf-8 on line 37 / / change the content of line 39 to support utf-8 (Chinese character set) 43 location / {44 root html; 45 index index.html index.htm; 46} / / add a status statistical parameter location / status {stub_status on; # # Statistical Module to open access_log off under line 46 # # access log off} step 2: install and configure the DNS service [root@localhost ~] # yum-y install bind// install the bind package of the DNS service [root@localhost ~] # vim / etc/named.conf / / Edit the main configuration file options {listen-on port 53 {any;} # # replace the listening address 127.0.0.1 with any, listen-on-v6 port 53 {:: 1;}; directory "/ var/named"; dump-file "/ var/named/data/cache_dump.db"; statistics-file "/ var/named/data/named_stats.txt"; memstatistics-file "/ var/named/data/named_mem_stats.txt" Recursing-file "/ var/named/data/named.recursing"; secroots-file "/ var/named/data/named.secroots"; allow-query {any;}; # # replace authorization localhost with any [root@localhost ~] # vim / etc/named.rfc1912.zones / / Edit zone configuration file zone "bdqn.com" IN {type master # # replace localhost with domain name bdqn.com file "bdqn.com.zone"; # # specify bdqn.com.zone allow-update {none;};} [root@localhost ~] # cd / var/named [root@localhost named] # cp-p named.localhost bdqn.com.zone / / copy zone data configuration file template is bdqn.com.zone [root@localhost named] # vim bdqn.com.zone / / Edit zone data configuration file $TTL 1D @ IN SOA @ rname.invalid. (0; serial 1D; refresh 1H; retry 1W; expire 3H) Minimum NS @ A 127.0.0.1www IN A 192.168.235.158delete the content of the last line Add the domain name resolution address to the local address [root@localhost named] # systemctl start named / / enable the dns service [root@localhost named] # systemctl stop firewalld.service / / turn off the firewall [root@localhost named] # setenforce 0 / / turn off the enhanced security function step 3: turn on the virtual machine test access status statistics of a WIndows system

Nginx access control authorization

1. Generate user password authentication file

two。 Modify the main configuration file to the corresponding directory and add the authentication configuration item

3. Restart the service and access the test

Step 1: modify Nginx.conf configuration file [root@localhost named] # vim / usr/local/nginx/conf/nginx.conf// edit Nginx.conf configuration file location / {auth_basic "secret"; # # verify that the type is secret auth_basic_user_file / usr/local/nginx/passwd.db # # specify the verification file path root html; index index.html index.htm } step 2: install the httpd-tools toolkit And specify the user name and password [root@localhost named] # yum install httpd-tools-y / install httpd-tools toolkit [root@localhost named] # htpasswd-c / usr/local/nginx/passwd.db test # # create the test user password authentication file New password: # # enter the password Re-type new password: # # confirm the password Adding password for user test [root@localhost named] # cat / usr/local/nginx/passwd.db## view Password file information test:$apr1 $mOje4UYz$BvRBABTcQB9XRG0SCCToZ1 [root@localhost named] # killall-1 nginx// overload nginx service step 3: use a test machine to verify the effect of access control authorization

The above is all the content of this Nginx website service, thank you for reading!

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report