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

How to set the number of mysql connections (Too many connections)

During the use of mysql, it was found that the nu...

MySQL 5.6.28 installation and configuration tutorial under Linux (Ubuntu)

mysql5.6.28 installation and configuration method...

JS realizes video barrage effect

Use ES6 modular development and observer mode to ...

Detailed explanation of the pitfalls of Apache domain name configuration

I have never used apache. After I started working...

Django+vue registration and login sample code

register The front-end uses axios in vue to pass ...

Analysis of the Nesting Rules of XHTML Tags

In the XHTML language, we all know that the ul ta...

Detailed explanation of javascript knowledge points

Table of contents 1. Basic Introduction to JavaSc...

Implementation of React virtual list

Table of contents 1. Background 2. What is a virt...

Solve the error problem caused by modifying mysql data_dir

Today, I set up a newly purchased Alibaba Cloud E...

In-depth analysis of MySQL deadlock issues

Preface If our business is at a very early stage ...

Multiple methods to modify MySQL root password (recommended)

Method 1: Use the SET PASSWORD command MySQL -u r...

Detailed explanation of cross-usage of Ref in React

Table of contents 1. First, let’s explain what Re...

How to display a small icon in front of the browser URL

When you browse many websites, you will find that ...

Manually install mysql5.7.10 on Ubuntu

This tutorial shares the process of manually inst...

Tutorial on Installing Nginx-RTMP Streaming Server on Ubuntu 14

1. RTMP RTMP streaming protocol is a real-time au...