Nginx source code compilation and installation process record

Nginx source code compilation and installation process record

The installation of the rpm package is relatively simple and will not be explained here.
For most open source software, if you can't find the installation package, you can use the source code installation method. Although source code installation is not as convenient as tools such as yum and apt, it is very common and can be used on servers with different CPU architectures and different operating systems.
The general way to compile and install using source code is to search for the corresponding software name on GitHub, find the source code, select the appropriate version, and then check the readme.md file in the source code directory (this file on GitHub is actually the description document of the source code). If the readme.md does not contain instructions on the steps of compiling and installing or building the project, it will also indicate where to get the corresponding documentation. The build documentation of some software is also written in a file called INSTALL. If the readme.md document does not have build instructions, you can try to find the INSTALL file.

For C language software, the steps for source code compilation are usually:
./configure
make
make install
Usually, the ./congfigure command checks the compilation environment based on the server CPU architecture and operating system, such as whether the required dependent components and library files are installed. You can also specify the installation location and some configuration items through parameters.
The make command can specify the number of CPU cores through the -j parameter. The more cores used, the faster the compilation speed. For example, for a server with 8 cores, you can use make -j8 to speed up the compilation speed.
Make install to install the software

For nginx, the source code compilation and installation steps are as follows:
wget https://nginx.org/download/nginx-1.14.2.tar.gz
tar -xvf nginx-1.14.2.tar.gz
cd nginx-1.14.2

./configure -prefix=/usr/local/nginx -with-http_ssl_module
make -j8
make install

/usr/local/nginx/sbin/nginx –v
The installation directory is specified as /usr/local/nginx during ./configure, so after installation, the nginx command is in this directory

If you need to deploy static pages such as HTML, upload the static file resources to the /usr/local/nginx/html/ directory.
Edit the nginx configuration file /usr/local/nginx/conf/nginx.conf and change the user in the second line to root or the current user. vim text editor, enter :set nu to display the number of lines.

Uncomment line 2 and change nobody to root:

If the web application needs to support uploading files, you need to set the upper limit of the uploaded files. Add the following to line 18:

client_max_body_size 100m;

If you need to change the access port of static resources, just modify it in line 37, for example, set it to 8081:

If you need to support request forwarding (for example, to access the backend interface in static resources, all requests to access /api are forwarded to the application on port 18080), add the following content to line 49:

location /chat/api{
            proxy_pass http://127.0.0.1:18080/api;
            proxy_redirect off;
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection 'upgrade';
	} 

The above configuration forwards all requests containing /chat/api/ in the access path to http://127.0.0.1:18080/api, where chat is the deployed static resource directory. The last two lines of configuration are used to support websocket connections, that is, the ws protocol.

With such a configuration, the front-end and back-end of the web application can be separated, that is, the front-end static resources are deployed on port 8081, and the back-end resources are deployed on port 18080. After deployment, you only need to start nginx and the application on port 18080 to access the web application normally.

This is the end of this article about Nginx source code compilation and installation. For more relevant Nginx source code compilation and installation content, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of Centos7 source code compilation and installation of Nginx1.13
  • How to install Nginx source code
  • Detailed explanation of nginx source code analysis configure script
  • Detailed explanation of nginx source code analysis thread pool

<<:  Use iframe to display weather effects on web pages

>>:  Some CSS questions you may be asked during an interview

Recommend

Use of Vue3 pages, menus, and routes

Table of contents 1. Click on the menu to jump 1....

How to completely uninstall node and npm on mac

npm uninstall sudo npm uninstall npm -g If you en...

Implementation of Docker private warehouse registry deployment

As more and more Docker images are used, there ne...

Use pure CSS to disable the a tag in HTML without JavaScript

In fact, this problem has already popped up when I...

Problems and solutions of using jsx syntax in React-vscode

Problem Description After installing the plugin E...

Ubuntu 20.04 Best Configuration Guide (Newbie Essential)

1. System Configuration 1. Turn off sudo password...

Navicat Premium operates MySQL database (executes sql statements)

1. Introduction to Navicat 1. What is Navicat? Na...

Implementation of Single Div drawing techniques in CSS

You can often see articles about CSS drawing, suc...

PHP-HTMLhtml important knowledge points notes (must read)

1. Use frameset, frame and iframe to realize mult...

13 JavaScript one-liners that will make you look like an expert

Table of contents 1. Get a random Boolean value (...

Detailed analysis of each stage of nginx's http request processing

When writing the HTTP module of nginx, it is nece...

HTML+CSS to achieve charging water drop fusion special effects code

Table of contents Preface: accomplish: Summarize:...

How to enable or disable SSH for a specific user or user group in Linux

Due to your company standards, you may only allow...

Detailed explanation of the problems and solutions caused by floating elements

1. Problem Multiple floating elements cannot expa...