Introduction: nginx is a high-performance http and reverse proxy server, concurrency is very strong, generally used to do load balancing more, daily development as a web server
I. Download nginx
Address:nginx: download
Let's download this stable version
II. Environmental dependency checks
The nginx installation requires a lot of external dependencies, first login to the linux server
2.1 gcc check
gcc -v
The following appears, indicating that gcc is installed
If the last line does not show the corresponding gcc version, then you have to download it manually. The following section is for downloading and installing various dependencies.
Provide an AliCloud mirror address:centos-7-os-x86_64-Packages installation package download_Open Source Mirror Station-Aliyun
gcc manifest
cpp-4.8.5-44.el7.x86_64.rpm gcc-4.8.5-44.el7.x86_64.rpm glibc-devel-2.17-317.el7.x86_64.rpm glibc-headers-2.17-317.el7.x86_64.rpm kernel-headers-3.10.0-1160.el7.x86_64.rpm libmpc-1.0.1-3.el7.x86_64.rpm mpfr-3.1.1-4.el7.x86_64.rpm
One by one to find the download, a small trick: you can directly copy the name to locate, ctrl + f
Upload the downloaded gcc dependencies to a folder on the server, or upload the zip package provided by the author, and unzip it, here are a few unzip related commands
1. Extract the zip file to the current directory:
unzip
2. Extract the zip file to the specified directory:
unzip -d /path/to/directory
3. View the contents of a zip file without extracting it:
unzip -l
If the unzip command is not installed, it can be installed in most Linux distributions with the following command (requires a network connection):
sudo apt install unzip # For Debian-based distributions (e.g. Ubuntu) sudo yum install unzip # For those who are based onRPMoperating system(as ifFedora、CentOS)
If you don't want to install unzip, just upload them all to a separate folder.
Then execute the following command in this folder
rpm -Uvh *.rpm --nodeps --force
2.2 PCRE examination
The following is from Baidu Encyclopedia:
- PCRE (Perl Compatible Regular Expressions) is a Perl library that includes a library of perl compatible regular expressions.
- These are useful in performing regular expression pattern matching with the same syntax and semantics as Perl 5.
- Boost is so huge that the compilation of the program slows down significantly after using boost regex.
- After testing, the same program takes 3 seconds to compile with boost::regex and less than 1 second with pcre.
- So instead use pcre to solve the problem of using regular expressions in C
Why do I need this library? Because nginx is developed in C, and this library is used for high performance.
Execute the
rpm -qa | grep pcre
You can see that the author's server already has this dependency installed
If these messages do not appear it means that it is not installed and needs to be downloaded by itself
Download Address:/
There's a version of it.
Translate:
There are two major versions of the PCRE library. The current version, PCRE2, was released in 2015 and is currently at version 10.39.
The older but still widely deployed PCRE library was originally released in 1997 as version 8.45.This version of PCRE is now end-of-life and is no longer actively maintained.Version 8.45 is expected to be the final version of the old PCRE library, and new projects should use PCRE2.
Keep clicking on this. The extranet's a little slow.
There are many versions, here is an example of the latest version
Download it and upload it to a folder on your linux server.
Execute the decompression command
tar -xvf pcre2-10.
cd into the unzipped directory and run
./configure (This can be followed by --prefix=yourpath,Install to the specified path,Generally not added,Just install it in the default path) make make install
2.3 zlib check
Baidu Presents:
- zlib is an open source software library for data compression and decompression. It uses a compression algorithm for DEFLATE, which can effectively compress and decompress most data.
- zlib can be widely used in many different applications, such as compression of software installation packages, compression of database files, compression of network data transfer, etc. It can be used in a wide range of applications. It is easy to use, supports many programming languages, and has high compression and decompression rates.
- The advantages of zlib are that it can compress and decompress most data efficiently, it is easy to use, it supports multiple programming languages, and it has high compression and decompression rates. The disadvantage is that the compression rate is not as high as some other algorithms, such as bzip2 and LZMA.
- zlib is a lightweight library that can be used on different system platforms. Its source code can be downloaded for free on the web and is highly portable. zlib supports the compression format DEFLATE, which can efficiently compress and decompress most data.
- zlib provides a set of simple functions to realize the compression and decompression of data. It supports a variety of programming languages, such as C, C++, Java, Python, etc., can be easily used in these languages. zlib provides functions including compress function to compress data and uncompress function to decompress data. These two functions are very simple to use, you only need to provide the data to be compressed or decompressed and the address of the target buffer.
- zlib also provides some advanced functions that can support more complex compression and decompression operations. For example, you can use the deflateInit, deflate and deflateEnd functions for streaming compression, and you can use the inflateInit, inflate and inflateEnd functions for streaming decompression.
- Overall, zlib is a very convenient data compression and decompression tool, it can effectively compress and decompress most of the data, and easy to use, support a variety of programming languages.
Execute the
rpm -qa | grep zlib
The author's linux system already has zlib installed.
No information as above, to download and install
Address:zlib Home Site
zlib was developed by these two, the former wrote the compression algorithm and the latter wrote the decompression algorithm
Scroll down, find this and click download.
Download it and upload it to a folder on your server.
Execute the decompression command
tar -zxvf
Then cd to the unpacked zlib directory and execute it in order
./configure (This can be followed by --prefix=yourpath,Install to the specified path,Generally not added,Just install it in the default path) make make install
2.4 openssl check
On the server, enter
openssl version
I'm sorry, the author's server has also installed openssl, you do not appear to correspond to the message, you need to download and install their own
Download Address:[ Downloads ] - /source/
Here's an example of the latest version
Once downloaded, the same is uploaded to a folder on the server to be unzipped
execute a command
tar -zxvf openssl-3.3.
Then go to the extracted directory and do the following
./configure (This can be followed by --prefix=yourpath,Install to the specified path,Generally not added,Just install it under the default path.) make make install
Third, install nginx
Once all the external dependencies are in place, you can install nginx
First of all, download the nginx zip package uploaded to the server under a file, the author here uploaded to /opt/nginx under the
Execute the following commands in sequence
cd /opt/nginx tar -zxvf nginx-1.24. cd nginx-1.24.0/
Go to the extracted folder and do the following, here configure the installation to /usr/local
./configure (--prefix=/usr/local/nginx,This specifies a path to install to,If you do not specify the,By default, it is also installed in this path,hasn'tnginxThe folder is automatically created) make make install
I got an error after the first sentence here, I reinstalled the PCRE library (following the pcre process above)
Once installed then go to the nginx decompression directory
Execute this . /configure
make make install
IV. Starting nginx
Then start nginx
cd /usr/local/nginx/sbin/ ./nginx
The default startup port for nginx is 80
Enter the following command to view port 80
sudo lsof -i :80
You can see that port 80 is being listened on by nginx
Open up access to port 80.
-- open-minded 80 ports access authority sudo firewall-cmd --permanent --add-port=80/tcp -- Reload Firewall sudo firewall-cmd --reload
Browser visit: 192.168.19.16:80 ,that nginx startup success!
Modify the port, for example, change it to 8081 (note that the firewall on port 8081 is opened first, refer to the command above)
cd /usr/local/nginx/conf vim
Press i to change the listening port to 8081.
esc Exit, type :wq to save
Execute the following command again
cd /usr/local/nginx/sbin/ ./nginx
At this point the browser visits 192.168.19.16:8081 and the modification is successful
Here's a question, the previous port 80, nginx service I did not deactivate, the browser to open 192.168.19.16:80, still can access the
The server looks at ports 80 and 8081 and finds that both are being listened to by nginx
Since you've changed the port, you shouldn't be listening on the original one anymore, killing the port 80 pid that corresponds to the nginx port
kill 22698
I found that port 80 is no longer being listened to by nginx, it's released, and browsers can't access it.
At this point, nginx is up and running.
V. Setting up boot-up
Here we use the Systemd method, nginx as a system service, set boot self-start
First execute the following command
sudo vim /etc/systemd/system/
Create a nginx system service file, press i and enter the following, esc to exit, :wq to save
Note that /usr/local/nginx should be replaced with your own nginx installation path (not the unzip path).
nginx -s quit # This method is milder than STOP and requires the process to finish its current work before stopping. nginx -s stop # Immediate cessation of services It's a tougher approach.,Whether the process is working or not,They all just stop the process.
If you want to exit nginx gently, ExecStop is replaced with the following
ExecStop=/usr/local/nginx/sbin/nginx -s quit
[Unit] Description=The nginx HTTP and reverse proxy server After= [Service] Type=forking ExecStartPre=/usr/local/nginx/sbin/nginx -t ExecStart=/usr/local/nginx/sbin/nginx ExecReload=/usr/local/nginx/sbin/nginx -s reload ExecStop=/usr/local/nginx/sbin/nginx -s stop [Install] WantedBy=
After saving and exiting the above, execute the following commands in turn
Kill the previously started nginx service process first.
Refresh Configuration
sudo systemctl daemon-reload
Allow nginx to self-start
sudo systemctl enable
Start nginx
sudo systemctl start
View a list of services that start up on boot
systemctl list-units --type=service
Check the status of the nginx service
sudo systemctl status
You can access it by typing 192.168.19.16:8081 into your browser.
Stopping the nginx service
sudo systemctl stop
reboot reboot to verify that nginx is booting from boot
summarize
The above is a personal experience, I hope it can give you a reference, and I hope you can support me more.