Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.
introduce
Nginx (Engine X) is a high-performance HTTP and reverse proxy Web server that also provides IMAP/POP3/SMTP services. Nginx was developed by Igor Sesoyev for the second most visited rambler.ru site in Russia (р а блер), the first public version 0.1.0 was released on 4 October 2004.
It distributes source code under a BSD-like license and is known for its stability, rich feature set, simple configuration files, and low system resource consumption. On June 1, 2011, Nginx 1.0.4 was released.
Nginx is a lightweight Web/reverse proxy server and E-mail (IMAP/POP3) proxy server distributed under the BSD-like protocol. It is characterized by less memory and strong concurrency. In fact, NGINx’s concurrency is better in the same type of web server.
— from Baidu Baike
installation
The source code to install
Source compilation can specify which modules to install:
[root@localhost /]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module
Copy the code
If the module is missing, it needs to be recompiled:
[root@localhost /]# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module
Copy the code
However, make is not required to avoid overwriting the original nginx directory
The RPM installation
Download RPM package address:
[root @ localhost opt] # wget < https://centos.pkgs.org/7/getpagespeed-x86_64/nginx-1.18.0-1.el7.ngx.x86_64.rpm.html > [root@localhost opt]# rpm -i [nginx - 1.18.0-1. El7. NGX. X86_64. RPM] (HTTP: / / https://centos.pkgs.org/7/getpagespeed-x86_64/nginx-1.18.0-1.el7.ngx.x86_64.rpm.html )Copy the code
The RPM installation package does not have this problem, but it is installed after the command: /usr/sbin/nginx, need to overwrite or recreate the soft chain /usr/bin/nginx
About RPM Uninstall
[root @ localhost opt] # RPM - qa | grep nginx nginx 1.18.0-1. El7. NGX. X86_64 [root @ localhost opt] # RPM -e Nginx 1.18.0-1. El7. NGX. X86_64Copy the code
If nginx does not have the --with-http_stub_status_module module, add the following configuration, the -t test will fail.
location /nginx_tatus {
stub_status on;
access_log off;
}
[root@localhost /]# nginx -t
[root@localhost /]# nginx -s reload # static loading
Copy the code
Visit: http://192.168.2.58/ng_status
Active connections: 2 server accepts handled requests 42 42 198 Reading: 0 Writing: 1 Waiting: 4 Active Connections - Nginx accepts 2 Active connections. Server accepts 42 connections since Nginx started. Server accepts 42 handshakes since Nginx started Writing -- Waiting -- Response data to client -- With keep-alive enabled, this is equal to active -- (Reading +writing) means that Nginx has finished processing the resident connection that is waiting for the next request instructionCopy the code
Enable nginx service logs
log_format main '$remote_addr - $remote_user [$time_local]
"$request" ' '$status $body_bytes_sent "$http_refer
'"$http_user_agent" "$http_x_forwarded_for"'; access_log logs/access.log main;
Copy the code
See the log
[root@localhost conf]# tail -f logs/access.log 192.168.2.188 - - [21/Oct/ 201:18:55:22 +0800] "GET / jforum/ping_session. JSP HTTP / 1.1 "200 376" http://192.168.2.58/jforum/ping_session.jsp "" Mozilla / 5.0 (Windows NT 10.0; Win64; X64) AppleWebKit / 537.36 (KHTML, Like Gecko) Chrome/92.0.4515.131 Safari/537.36" "-" 192.168.2.188 - - [21/Oct/ 201:18:56:22 +0800] "GET / jforum/ping_session. JSP HTTP / 1.1 "200 376" http://192.168.2.58/jforum/ping_session.jsp "" Mozilla / 5.0 (Windows NT 10.0; Win64; X64) AppleWebKit / 537.36 (KHTML, Like Gecko) Chrome/92.0.4515.131 Safari/537.36" "-" 192.168.2.188 - - [21/Oct/ 201:18:57:22 +0800] "GET / jforum/ping_session. JSP HTTP / 1.1 "200 376" http://192.168.2.58/jforum/ping_session.jsp "" Mozilla / 5.0 (Windows NT 10.0; Win64; X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36" -"Copy the code
Nginx configuration optimization
Nginx.conf is configured globally; Connection pool events {worker_connections 20; } Worker_processes 1; Some compressed gzip on; #, etc.Copy the code