Nginx-Web Service Configuration and Testing

(1) Introduction of software
Developed by lgor Sysove, a Russian, for open source software.
Supporting high concurrency: Supporting tens of thousands of concurrent connections (especially static small file business environments)
Less resource consumption: Opening 10 Nginx threads under 30,000 concurrent connections consumes less than 200 M of memory
Support for asynchronous network I/O event model epoll (Linux 2.6+) Apache (select)
Introduction to Functions
1. As a web server software (handling user access static requests)
2. Reverse proxy or load balancing services
3. Front-end business data caching service
Characteristics of Nginx Software Model
apache uses select model to search one by one
nginx searches after using epoll model
(2) Installation of Nginx software
1. Dependent installation method: first install dependent packages
pcre-devel: perl Language Regular Expression Compatibility Package
openssl-devel: Make the system support https

[root@web02 ~]# yum install -y pcre-devel openssl-devel
[root@web02 ~]# cd /server/tool/
[root@web02 tool]# wget Download Software on Official Website
[root@web02 tool]# tar zxf nginx-1.16.1.tar.gz Unzip the file
[root@web02 tool]# ll
total 1016
drwxr-xr-x. 8 1001 1001 4096 Aug 13 20:51 nginx-1.16.1
-rw-r--r--. 1 root root 1032630 Aug 14 01:01 nginx-1.16.1.tar.gz

2. Create management nginx management users

[root@web02 nginx-1.16.1]# useradd www -s /sbin/nologin -M

3. Compile and install nginx software (/ server/tool/nginx-1.16.1 / decompressed file directory)

[root@web02 nginx-1.16.1]# ./configure --prefix=/app/nginx-1.16.1 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
[root@web02 nginx-1.16.1]# make && make inistall
[root@web02 nginx-1.16.1]# cd /app/nginx-1.16.1/
[root@web02 nginx-1.16.1]# ll
total 16
drwxr-xr-x. 2 root root 4096 Aug 19 16:34 conf
drwxr-xr-x. 2 root root 4096 Aug 19 16:34 html
drwxr-xr-x. 2 root root 4096 Aug 19 16:34 logs
drwxr-xr-x. 2 root root 4096 Aug 19 16:34 sbin

4. Create soft links

[root@web02 app]# ln -s /app/nginx-1.16.1/ /app/nginx

(3) Start Nginx software testing

[root@web02 app]# /app/nginx/sbin/nginx 
[root@web02 app]# ps-ef | grep nginx checks whether the process is enabled
Root 16565 10117:10? 00:00 nginx: master process/app/nginx/sbin/nginx manages nginx software services
Www 16566 16565 0 17:10? 00:00 nginx: worker process worker process worker process (adjustments needed to address high concurrent access)
root 16568 16527 0 17:10 pts/1 00:00:00 grep nginx
[root@web02 nginx]# grep -Ev "#|^$" ./conf/nginx.conf.default > ./conf/nginx.conf 
Filter out useless well number information and blank lines

(4) Creating a directory of www sites

[root@web02 html]# mkdir -p /app/nginx/html/www
[root@web02 html]# cat /app/nginx/html/www/index.html

(5) Standardization of site catalogue creation in batches

[root@web02 ~]# for name in www pho blog;do echo " $" > /app/nginx/html/$name/index.html;done
[root@web02 ~]# for name in www pho blog;do cat /app/nginx/html/$name/index.html;done
[root@web02 conf]# sed -n '10,17p' nginx.conf
server {
listen 80;
location / {
root html/www;
index index.html index.htm;
[root@web02 conf]# sed -n '10,17p' nginx.conf > extra/www.conf
[root@web02 conf]# sed -n '10,17p' nginx.conf > extra/pho.conf
[root@web02 conf]# sed -n '10,17p' nginx.conf > extra/blog.conf
[root@web02 conf]# /app/nginx/sbin/nginx -t
nginx: the configuration file /app/nginx-1.16.1/conf/nginx.conf syntax is ok
nginx: configuration file /app/nginx-1.16.1/conf/nginx.conf test is successful
[root@web02 conf]# /app/nginx/sbin/nginx -s reload

(6) Testing website visits
1. Modify hosts file to add domain name information

[root@web02 conf]# cat /etc/hosts web02 

2. Use curl command to check whether static websites display successfully

[root@web02 ~]# curl
[root@web02 ~]# curl
[root@web02 ~]# curl

(7) Nginx startup command parameters (command parameters under sbin directory)* must use full paths
- V. View nginx software compilation configuration parameters (how to install nginx software)
- v. View nginx version information
- t. Check that the nginx configuration file grammar format is correct
- s) Used to manage the running status of nginx services (syntax error or not)
stop the nginx service
Reload reload reload nginx service
Really restarting nginx service is restarting service /*. / nginx-s stop after stopping and restarting nginx

[root@web01 ~]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.16/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.16/conf/nginx.conf test is successful
[root@web01 ~]# /application/nginx/sbin/nginx -s reload
[root@web01 ~]# /application/nginx/sbin/nginx -s stop

(8) Nginx log-related settings
1. Error log configuration method: add log information after the main module of nginx.conf configuration file
The error_log log log level is divided into: debug,info,notice,warn,error,crit (default crit)

error_log   logs/error.log    error
Error Log, Storage Location, Log Level

2. Access log access.log configuration method: (configure in http module)

log_format main '$remote_addr - $remote_user [$time_local] "$request"'  #Define log information record content
          '$status $body_bytes_sent "$http_referer"'          
          '"$http_user_agent" "$http_x_forwarded_for"';    
access_log   logs
/access.log   main;     #Call Definition Format Information (log_format main)Generate access logs
Access Log       Storage location    Start Access Logging

2.1 access access log content meaning:

$remote_addr Access client source address information
remote_user - - Access client authentication user information
[$time_local]] Displays access time
GET/HTTP/1.1 Displays request information
status 304 status Code Information (304 Displays Page Information with Cache)
Record domain name information linked to the website


Tags: Linux Nginx curl less Apache

Posted on Mon, 19 Aug 2019 21:09:14 -0700 by d-Pixie