preface
Recently, projects are often deployed in the company, but the server environment is already set up by the tutor. I just put the project files into a specific directory. So, the weekend at home for Nginx installation learning. Previously, Nginx has been used on Windows, but there is a certain difference between the installation of Ngnix in Linux environment and that in Windows environment. This time, the installation of Nginx using the source code package in the Linux environment encountered a lot of problems, but looked up some information also solved. Hopefully the following notes will help you avoid these problems.
Two ways to install Linux
First, let’s look at how Linux is installed, either by YUM or source bundle.
- Yum installation: Simple and easy to error.
- Source package installation: a bit cumbersome, but good service performance.
Yum install
1. Install Nginx
Nginx installation is as simple as typing a command.
$ sudo yum -y install nginx # to install nginx
$ sudo yum remove nginx # uninstall nginx
Copy the code
Nginx configuration file in /etc/nginx directory
Configure the Nginx service
$ sudo systemctl enable nginx Set boot up
$ sudo service nginx start # Start nginx service
$ sudo service nginx stop # Stop nginx service
$ sudo service nginx restart Restart the nginx service
$ sudo service nginx reload Reloading the configuration is usually used when the nginx configuration file has been modified.
Copy the code
Source package installation
Nginx source package installation is cumbersome and requires the installation of some Nginx dependent libraries in advance.
Dependent library installation
1. Install the GCC environment
$ sudo yum -y install gcc gcc-c++ # nginx relies on the GCC environment for compilation
Copy the code
2. Installing pcre
$ sudo yum -y install pcre pcre-devel # Enable nginx to support rewriting
Copy the code
3. Install the zlib
Nginx uses zlib for gzip compression of HTTP package contents
$ sudo yum -y install zlib zlib-devel
Copy the code
4. Install openssl
Secure Socket Layer password library for communication encryption
$ sudo yum -y install openssl openssl-devel
Copy the code
After the above installation is complete, proceed with the nginx installation.
Nginx source package installation
Copy the prepared nginx-1.11.5.tar.gz package to the /usr/local/nginx directory and decompress it.
Source code package download address: nginx.org/en/download…
$sudo tar -zxvf nginx-1.11.5.tar.gz# decompression
Copy the code
After the decompression, enter the nginx-1.11.5 directory for source code compilation and installation.
$ cdNginx - 1.11.5 $. / configure -- prefix = / usr /local/nginx Check the platform installation environment
# --prefix=/usr/local/nginx is the directory where nginx is compiled and installed (recommended)
Copy the code
/configure –prefix=/usr/local/nginx will display some environment information if the preceding libraries are successfully installed. If an error occurs, the dependency library is not installed. You can install the missing dependency library according to the error message.
Compile the source code and install nginx
$ make # compiler
$ make install # installation
Copy the code
The source package installation is also different from the Nginx service operation commands installed by YUM.
- Start the service
$ /usr/local/nginx/sbin/nginx
Copy the code
- Reload the service
$ /usr/local/nginx/sbin/nginx -s reload
Copy the code
- Stop the service
$ /usr/local/nginx/sbin/nginx -s stop
Copy the code
View the nginx server process
$ ps -ef | grep nginx # Check the server process
Copy the code