How to install Nginx in CentOS7 and configure automatic startup

How to install Nginx in CentOS7 and configure automatic startup

1. Download the installation package from the official website

http://nginx.org/en/download.html, select the version suitable for Linux, here choose the latest version, download it locally and upload it to the server or directly download it with the wget command under centos.

Switch to the /usr/local directory and download the software package

# cd /usr/local
# wget http://nginx.org/download/nginx-1.11.5.tar.gz

2. Install nginx

First execute the following command to install the nginx dependency library. If the dependency library is missing, the installation may fail. For details, please refer to the error message at the end of the article.

# yum install gcc-c++
# yum install pcre
# yum install pcre-devel
# yum install zlib 
# yum install zlib-devel
# yum install openssl
# yum install openssl-devel

Unzip the installation package

# tar -zxvf nginx-1.11.5.tar.gz

nginx is unzipped to the /usr/local/nginx-1.11.5 directory (do not unzip the compressed package to the /usr/local/nginx directory, or rename the unzipped directory to nginx, because nginx will be installed to the /usr/local/nginx directory by default), switch to the nginx-1.11.5/ directory

# cd /usr/local/nginx-1.11.5/

Execute # ./configure

# ./configure

This operation will detect the current system environment to ensure that nginx can be successfully installed. After performing this operation, the following prompts may appear:

checking for OS

+ Linux 3.10.0-123.el7.x86_64 x86_64

checking for C compiler ... not found

./configure: error: C compiler cc is not found

If the above error message appears, execute yum install gcc-c++ to install gcc.

./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.

If the above prompt appears, it means that the PCRE library is missing

./configure: error: the HTTP gzip module requires the zlib library.

You can either disable the module by using --without-http_gzip_module

option, or install the zlib library into the system, or build the zlib library

statically from the source with nginx by using --with-zlib=<path> option.

If the above prompt appears, it means that the zlib library is missing

If the ./configure: error prompt does not appear, it means that nginx can be installed in the current environment. Execute make and make install to compile nginx.

# make
# make install

If there is no error, it means that nginx has been successfully installed. The default installation location is /usr/local/nginx. The previous /usr/local/nginx-1.11.5/ can be deleted.

If the message cp: 'conf/koi-win' and '/usr/local/nginx/conf/koi-win' are the same file appears, it may be that you have unzipped the installation package to the /usr/local/nginx directory. The solution is to rename the directory to another name and then execute make, make install.

3. Configure nginx to start up

Switch to the /lib/systemd/system/ directory and create the nginx.service file vim nginx.service

# cd /lib/systemd/system/
# vim nginx.service

The file contents are as follows:

[Unit]
Description=nginx 
After=network.target 
 
[Service] 
Type=forking 
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx reload
ExecStop=/usr/local/nginx/sbin/nginx quit
PrivateTmp=true 
 
[Install] 
WantedBy=multi-user.target

Exit and save the file, execute systemctl enable nginx.service to start nginx at boot

# systemctl enable nginx.service

systemctl start nginx.service starts nginx

systemctl stop nginx.service ends nginx

systemctl restart nginx.service restart nginx

4. Verify whether the installation is successful

Enter http://server IP/ If you can see the nginx interface, it means the installation is successful

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Installation and configuration method of Nginx+PHP5 under Windows
  • CentOS 6.4 installation and configuration of LNMP server (Nginx+PHP+MySQL)
  • Install and configure php-fpm to build a production environment of Nginx+PHP
  • Tutorial on installing and configuring nginx to support PHP (full)
  • Install and configure Nginx on CentOS 7
  • Installation, configuration and use of nginx under Windows
  • Detailed explanation of Nginx installation environment configuration under Mac
  • Tutorial on installing and configuring PHPMyAdmin on Nginx server
  • Detailed explanation of installing and configuring nginx under Linux
  • Detailed process record of nginx installation and configuration

<<:  Detailed explanation of Nest.js environment variable configuration and serialization

>>:  A brief discussion on MySQL index design principles and the differences between common indexes

Recommend

Analysis of MySQL latency issues and data flushing strategy process

Table of contents 1. MySQL replication process 2....

How to deploy Vue project under nginx

Today I will use the server nginx, and I also nee...

Nginx server https configuration method example

Linux: Linux version 3.10.0-123.9.3.el7.x86_64 Ng...

Network configuration of Host Only+NAT mode under VirtualBox

The network configuration of Host Only+NAT mode u...

Two ways to enable firewall in Linux service

There are two ways: 1. Service method Check the f...

Use vue2+elementui for hover prompts

Vue2+elementui's hover prompts are divided in...

How to use CSS to center a box horizontally and vertically (8 methods)

Original code: center.html : <!DOCTYPE html>...

How to get datetime data in mysql, followed by .0

The data type of MySQL is datetime. The data stor...

A brief analysis of the matching priority of Nginx configuration location

Preface The location in the server block in the N...