Technical Corner | "Source Production Control" Series (2) Using Nginx 1.18 on CentOS 8: Compile, Install and Basic Use

This is the second article in the series of "Source Production Control" in Huixiang Technology Corner.
**Author's note: **Huixiang technology corner "source production control" topic, will focus on the three directions of open source, localization, independent and controllable technology, with operating system, middleware, database, program application, etc. as the rough classification, update related The development trend of technology, the in-depth use of the core technology, and the systematic summary of the overall structure of the technology provide considerable information for learners of related technologies, and also provide personal synchronized learning and summary notes for readers.

This article introduces and summarizes the basic installation and basic usage of using Nginx 1.18 on CentOS 8. In the future, regarding the use of Nginx 1.18 on CentOS 8, the series of articles on its usage summary and performance tuning will be updated one after another. Please look forward to.

What is Nginx

Nginx (pronounced "engine X") is a web server with an asynchronous framework, and can also be used as a reverse proxy, load balancer, and HTTP cache. The software was created by Igor Sesoyev and released to the public for the first time in 2004. A company of the same name was established in 2011 to provide support. On March 11, 2019, Nginx was acquired by F5 Networks for US$670 million. Nginx is free and open source software, released under the terms of a BSD-like license. Most web servers use Nginx, usually as a [Load Balancing] (https://cloud.tencent.com/product/clb?from=10680) device.

The official website of the open source version is nginx.org. The official website of the commercial version is nginx.com.

But speaking of Nginx, I have to mention the arrest of the Nginx author after Nginx was acquired by F5. According to foreign media reports, on December 12, 2019, Russian police searched the commercial server company Nginx and took away the two co-founders on the spot. . Regarding this matter, I also used it as an example in the article ["What might change us under the war epidemic"] (http://mp.weixin.qq.com/s?__biz=MjM5NDAwNTQ0MA==&mid=2249483985&idx=1&sn=84b009e4e522929ad82cd0925a6573e1&chksm=a56eae7e921927683cda98fc32743681346e60155a296aece628f498838916527e5be8453b8a&scene=21#wechat_redirect) to explain some of the risks of personal branding and word-of-mouth shaping. Those who are interested can click in and take a look.

For Nginx, due to its rapid development, excellent performance, and open source, it has harvested many markets for web service provision, load balancing, and reverse proxy scenarios, and has also derived excellent secondary development versions such as OpenResty developed by Chinese people and open source by Ali Tengine etc. After the "Using Nginx 1.18 on CentOS 8" series, I will choose the opportunity to introduce two excellent secondary developments.

Install Nginx 1.18 on CentOS 8

Although we can install it through yum -y install nginx, it is introduced in the first article of the ["source production library" series "CentOS 8 first acquaintance"] (http://mp.weixin.qq.com/s?__biz=MjM5NDAwNTQ0MA==&mid=2249484093&idx=1&sn=25e98d52ec24f840e83a78d29a6c7f4f&chksm=a56eaf92921926840f0a8ae2592af72ff4c290a3053323bcdde29ab8bbdae54b81c10af8a87a&scene=21#wechat_redirect), the precompiled version of the mirror source It is 1.14, and as of the date of publication of the article, the stable version of Nginx has been updated to 1.18, and the mainline version has been updated to 1.19, so we use the stable source code version of the official website to download and compile.

Nginx version download page, as of the post (2020-07-07) the stable version has been updated to 1.18, and the mainline version has been updated to 1.19

Tips: About the stable version and the mainline version. The former is that Nginx updates to receive fixes for high-severity errors, but will not use the latest features. The second digit of its version number is represented by an even number. The latter is Nginx is an updated and active development branch, which adds the latest features and bug fixes, and the second digit of its version number is represented by an odd number. However, in Nginx, "stable" refers to features and update frequency, it has nothing to do with software quality. The stable branch never receives new features during its life cycle, and usually only receives one or two updates to fix serious bugs. The life cycle of a stable branch is generally one year. Every April, the official will stop the maintenance of the current stable branch and no longer provide bug fixes.

Download and unzip nginx-1.18.0.tar.gz:

wget http://nginx.org/download/nginx-1.18.0.tar.gz;
tar -zxvf nginx-1.18.0.tar.gz;

Enter the directory cd nginx-1.18.0, the directory structure is as follows:

Total amount 1204
drwxr-xr-x 6100110013267 month 718:50 auto
- rw-r--r--1100110013028634Month 2122:09 CHANGES
- rw-r--r--1100110014622134Month 2122:09 CHANGES.ru
drwxr-xr-x 2100110011687 July 718:50 conf
- rwxr-xr-x 11001100125024 month 2122:09 configure
drwxr-xr-x 410011001727 month 718:50 contrib
drwxr-xr-x 210011001407Month 718:50 html
- rw-r--r--11001100113974Month 2122:09 LICENSE
drwxr-xr-x 210011001217 718:50 man
- rw-r--r--110011001494Month 2122:09 README
drwxr-xr-x 910011001917 July 718:50 src

The conf folder is the initial configuration file of Nginx, the contrib folder contains the contents of three plug-ins contributed by three open source contributors, the html folder is the default site file content, and the src folder is the Nginx source code . The configure file is a compiled configuration file.

Copy the following files in the Nginx installation package to the path, so that vim can highlight and analyze the language syntax of nginx.conf:

cp -r contrib/vim/* ~/.vim/;

. /configure --help can view the Nginx compilation support parameter list. After the configure file is set, the files required for Nginx installation will be generated in the objs file, among which ngx_modules.c, the file determines the next compilation What modules need to be compiled into Nginx.

This article does not involve the compilation and use of modules, we use the simplest compilation settings to compile and install:

. /configure --prefix=/usr/local/nginx;

If the following error is reported, please execute the command yum -y install pcre-devel openssl openssl-devel to install:

...
checking for PCRE library ... not found
checking for PCRE library in/usr/local/... not found
checking for PCRE library in/usr/include/pcre/... not found
checking for PCRE library in/usr/pkg/... not found
checking for PCRE library in/opt/local/... not found

. /configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

When the following content appears, the setting of the configure file is complete:

Configuration summary
 + using system PCRE library
 + OpenSSL library is not used
 + using system zlib library

 nginx path prefix:"/usr/local/nginx/"
 nginx binary file:"/usr/local/nginx/sbin/nginx"
 nginx modules path:"/usr/local/nginx/modules"
 nginx configuration prefix:"/usr/local/nginx/conf"
 nginx configuration file:"/usr/local/nginx/conf/nginx.conf"
 nginx pid file:"/usr/local/nginx/logs/nginx.pid"
 nginx error log file:"/usr/local/nginx/logs/error.log"
 nginx http access log file:"/usr/local/nginx/logs/access.log"
 nginx http client request body temporary files:"client_body_temp"
 nginx http proxy temporary files:"proxy_temp"
 nginx http fastcgi temporary files:"fastcgi_temp"
 nginx http uwsgi temporary files:"uwsgi_temp"
 nginx http scgi temporary files:"scgi_temp"

Immediately execute the make command. After execution, you can see the compiled nginx binary file and object file in the objs folder. No error indicates normal. If you install Nginx for the first time, then execute make install to install it. If you are upgrading Nginx, make install should not be used. What needs to be done is to copy the nginx binary file generated in this directory to the corresponding directory of the existing Nginx binary file.

Initial use of Nginx 1.18 in CentOS 8

After the installation is complete, enter the following command to start Nginx:

/usr/local/nginx/sbin/nginx;

The basic instruction format of Nginx is nginx -s reload, and the specific instructions are explained as follows:

Visit the IP in the browser, as shown in the figure, it is normal if you can visit.

Visit the IP in the browser, as shown in the figure, it is normal

ps -ef | grep nginx to view the process:

root      85561019:24?00:00:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody    85578556019:24?00:00:00 nginx: worker process
root      85618702019:25 pts/000:00:00 grep --color=auto nginx

Now that the basic Nginx is installed, the complete nginx.conf file is as follows:

# user  nobody;
worker_processes  auto;

error_log  logs/error.log;
# error_log  logs/error.log  notice;
# error_log  logs/error.log  info;

pid        logs/nginx.pid;

events {
 worker_connections  1024;}

http {
 include       mime.types;
 default_type  application/octet-stream;

 log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';

 access_log  logs/access.log  main;

 server {
  listen       80;
  server_name  localhost;

  access_log  logs/host.access.log  main;

  location /{
   root   html;
   index  index.html index.htm;}

  error_page   500502503504/50x.html;
  location =/50x.html {
   root   html;}}}

Nginx configuration syntax has the following rules:

  1. The log file is composed of instructions and instruction blocks;
  2. Each instruction ends with ;, and the instructions and parameters are separated by spaces;
  3. The instruction block organizes multiple instructions together with {};
  4. The include statement allows multiple configuration files to be combined to improve maintainability;
  5. Use # to add comments to improve readability;
  6. Use $ to call variables;
  7. The parameters of some commands support regular expressions.

Nginx has a variety of command blocks, among which the http block indicates that this is the HTTP protocol processing block, the upstream indicates the configuration information provided by the upstream service, the expression of the URL corresponding to the location, and the server corresponds to one or a group of domains. /Domain name access.

The following is the parameter explanation of the configuration file part:

Regarding other parameters such as pid, worker_connections, etc., as well as the server, upstream, and location command blocks, they will be introduced and demonstrated in the subsequent "Using Nginx 1.18 on CentOS 8" series of articles. .

Reference

  1. Nginx mainline version 1.17.0 released, 1.14 stable branch has stopped maintenance
  2. Index - nginx.org
  3. Core functionality - nginx.org

Recommended Posts

Technical Corner | &quot;Source Production Control&quot; Series (2) Using Nginx 1.18 on CentOS 8: Compile, Install and Basic Use
&quot;Source Production Control&quot; series (2) Using Nginx 1.18 on CentOS 8: Compile, Install and Basic Use
CentOs7.3 compile and install Nginx 1.9.9
Technology Corner | &quot;Source Production Control&quot; series (1) First acquaintance with CentOS 8
CentOS 6.x compile and install Nginx
Technical Corner | Using Elastic Stack on CentOS 8: Elasticsearch/Kibana 7.8 Deployment and Authentication Configuration
How to install and use Docker on CentOS 7
&quot;Source Production Control&quot; series (1) First acquaintance with CentOS 8
How to install and use Composer on CentOS 8
How to install and use Curl on CentOS 8
How to install and use Cockpit on CentOS 8/RHEL 8
Compile and install the open source EDA tool-Surelog on CentOS8
Centos compile and install Git
Centos7 compile and install ntp-4.2.8p11
CentOS 6.9 compile and install python
CentOS 6 compile and install python 3
Install Nginx server on CentOS 7
CentOS Yum compile and install MySQL 5.6
Compile and install LAMP under Centos 5.2
CentOS 8 install Git and basic configuration
Use Nginx and u under CentOS
CentOS7 compile and install L(A|N)MP environment
How to install Nginx on CentOS 8
CentOS7.3 install iptables and detailed use
Install and use docker under CentOS 6.8
CentOS7 install and use SQL Server
Linux CentOS6 compile and install Pyt
Compile and install libmodbus library under CentOS7
CentOS7.5 source code compile and install mysql5.7.29
Install docker on ubuntu and basic usage
Centos7 compile and install MySQL8 problem record
Compile and install nodejs and yum in Centos8
CentOS7.4 source code compile and install MySQL8.0
Install VMware Fusion and CentOS-7 on Mac
How to install and configure Elasticsearch on CentOS 7
Install and use Git and GitHub on Ubuntu Linux
How to install and use Docker on Ubuntu 20.04
How to install and configure VNC on CentOS 8
How to install and use Curl on Ubuntu 18.04
How to install and use Composer on Ubuntu 18.04
How to install and use Wine on Ubuntu 18.04
How to install and configure Redis on CentOS 8
How to install Node.js and npm on CentOS 8
How to install and use Composer on Ubuntu 20.04
How to install and use BaasBox on Ubuntu 14.04
How to install and use PostgreSQL on Ubuntu 16.04
How to install jdk1.8.0_151 and mysql5.6.38 on centos7.2.1511
How to install and configure phpMyAdmin on CentOS 6
Centos6.5 compile and install LNMP architecture web environment
How to install and configure Owncloud on CentOS 8
Centos7.2 compile and install way to build phpMyAdmin
How to install and uninstall tomcat on centos
How to install and use Docker on Ubuntu 16.04
How to install and configure Redmine on CentOS 8