The Linux version of Nginx is recommended to be installed using source code.
Nginx installation
1. Environment preparation
To compile Nginx source code, we need a standard GCC compiler. GCC is the GNUCompiler Collection. Developed by GNU and distributed under the GPL and LGPL licenses, GCC is a standard compiler for free Unix-like and Mac OS X operating systems. GCC, originally known as the GNU C compiler because it could only handle C, has been rapidly expanded to handle other languages such as C++, Fortran, Pascal, Objective-C, Java, and Ada.
In addition, we need the Automake tool to automatically create makefiles.
Some Nginx modules also rely on third-party libraries, such as the PCRE library (which supports the rewrite module), the Zlib library (which supports the Gzip module), and the OpenSSL library (which supports the SSL module). So you need to install these libraries before compiling Nginx source code.
# yum -y install gcc-c++ # yum -y install pcre pcre-devel #zlib install yum -y install zlib-devel # yum -y install openssl openssl-develCopy the code
Not to mention the first three, many software will depend on the package. You need to install OpenSSL because nginx may need to configure HTTPS later, so it is best to prepare in advance.
Before proceeding with the above installation, it is best to use the following command to see if the packages have been installed.
yum list installed | grep ***
Copy the code
At this point the installation environment is ready.
Download Nginx from Nginx
After downloading the nginx package, upload it to the server and decompress it to go to the decompressed nginx directory.
2. Source code compilation
Nginx is easy to compile and install. It is recommended to download a tar file to install Nginx on Linux.
# ZXVF nginx-1.20.1.tar.gz # ZXVF nginx-1.20.1.tar.gz # ZXVF nginx-1.20.1.tar.gz /usr/local/nginx./configure /usr/local/nginx./configure /usr/local/nginx./ usr/local/nginx./configure /usr/local/nginxCopy the code
At this point, the Nginx installation is complete. The Nginx installation uses the default Nginx configuration.
3. Start the nginx
Start nginx in /usr/local/nginx/sbinCopy the code
Access the server IP address and display the welcome page of nginx
Common commands
/nginx -s quit # stop normal./nginx -s stop # stop fast./nginx -s reload # reload./nginx -v # Displays the version informationCopy the code
Nginx uninstall
1. The first type the command ps – ef | grep nginx check nginx service is running.
[root@zhaoym /]# ps -ef |grep nginx
root 7514 1 0 10:00 ? 00:00:00 nginx: master process ./nginx
root 7602 7514 0 10:12 ? 00:00:00 nginx: worker process
root 8144 2354 0 18:07 pts/0 00:00:00 grep --color=auto nginx
Copy the code
2. Stop the Nginx service
[root@zhaoym /]# /usr/local/nginx/sbin/nginx -s stop [root@zhaoym /]# netstat -lntp Active Internet connections (only Servers) Proto Recv -q Send -q Local Address Foreign Address State PID/Program name TCP 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1023/ SSHD TCP 0 0 0.0.0.0:5355 0.0.0.0:* LISTEN 979/systemd-resolve TCP 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7514/nginx: master tcp6 0 0 :::5355 :::* LISTEN 979/systemd-resolve tcp6 0 0 :::21Copy the code
3. Find and delete nginx-related files
-
Check out the Nginx file whereis Nginx
[root@zhaoym /]# whereis nginx
nginx: /usr/lib64/nginx /usr/local/nginx /usr/share/nginx
Copy the code
- Find Finds related files
[root@zhaoym /]# find / -name nginx
/var/lib/nginx
/var/log/nginx
/usr/lib64/nginx
/usr/share/nginx
/usr/local/nginx
/usr/local/nginx/sbin/nginx
Copy the code
- In turn to delete the find of all directories to find: rm – rf/usr/local/nginx/sbin/nginx
rm -rf /usr/local/nginx/sbin/nginx
Copy the code
4. Then use yum to clean it
[root@localhost /]# yum remove nginx = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Package source architecture version Size = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = are deleted: Nginx x86_64 1:1.12.2-3. el7@epel 1.5m Nginx-all-modules noarch 1:1.12.2-3.el7@epel 0.0 nginx-mod-http-geoip x86_64 1:1.12.2-3.el7@epel 21 K Nginx-mod-http-image-filter x86_64 1:1.12.2-3.el7@epel 24 k nginx-mod-http-perl x86_64 1:1.12.2-3.el7@epel 54 K Nginx-mod-http-xslt-filter x86_64 1:1.12.2-3.el7@epel 24 K nginx-mod-mail x86_64 1:1.12.2-3.el7@epel 99 k Nginx-mod-stream x86_64 1:1.12.2-3. el7@epel 157 k = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = remove 1 package (+ 7 Install size: 1.9m Do you want to continue? [y/N) :Copy the code