Get the App
SLTechnology News&Howtos  ›  Servers  › 

Installation method of Nginx in CentOS

Shulou Source: shulou.com Published: 2022-06-02 01:14:43 10月05日 Update

My machine is CentOS, so this article is based on CentOS installation. Nginx can be installed in two ways under CentOS, yum installation and source installation.

1. Yum installation

Yum installation is very simple, first of all, we also need to add the repository source of the EPEL package. Use the following command

Yum-y install epel-release

Then execute the install Nginx command.

Yum-y install nginx

II. Source code installation

For source code installation, you need to download the source code and the corresponding dependent package from the official website, and then compile and install it.

The packages that Nginx depends on are:

Openssl-devel

Zlib-devel

Pcre-devel

Gcc

In general, we only need to install zlib-devel and pcre-devel, gcc a lot of centos has been installed.

1. Install the PCRE library

# download, compile and install the latest PCRE source code package using the following command: ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ cd / opt/softwget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz tar-zxvf pcre-8.40.tar.gzcd pcre-8.40./configuremakemake install

two。 Install the zlib library

Cd / opt/softwget http://zlib.net/zlib-1.2.10.tar.gztar-zxvf zlib-1.2.10.tar.gzcd zlib-1.2.10./configuremakemake install

3. Install Nginx

Cd / opt/softwget http://nginx.org/download/nginx-1.4.2.tar.gztar-zxvf nginx-1.4.2.tar.gzcd nginx-1.4.2./configure makemake install

If you directly execute. / configure, nginx is installed to the default path (default path installation run / usr/local/nginx). The custom installation steps are as follows: install to the / soft/nginx directory

. / configure

-- sbin-path=/opt/soft/nginx/sbin

-- conf-path=/soft/nginx/nginx.conf

-- pid-path=/soft/nginx/nginx.pid

-- with-http_ssl_module

-- with-pcre=/opt/soft/pcre-8.40

-- with-zlib=/opt/soft/zlib-1.2.10

Note that it is consistent with the version number and directory of the installation, and the path of the dependent package.

III. Startup, restart and shutdown of Nginx

1. Firewall Settin

Through the above command operation, Nginx has been installed, we first need to open the firewall, open Nginx open port 80.

/ sbin/iptables-I INPUT-p tcp-- dport 80-j ACCEPT / etc/rc.d/init.d/iptables save / etc/init.d/iptables restart

two。 Start

Start Nginx and run the Nginx execution file directly

/ usr/local/nginx/sbin/nginx

3. Restart

/ usr/local/nginx/sbin/nginx-s restart

4. Close

/ usr/local/nginx/sbin/nginx-s stop

5. test

Later, we will configure the configuration file of Nginx. After modifying the configuration file, we can mirror the configuration file to determine whether the modified configuration is correct.

/ usr/local/nginx/sbin/nginx-t

After the above steps, start Nginx and visit port 80 of the server to see the welcome page of Nginx.

Tags: Source code configuration commands files paths steps directories ports firewalls installed tested compiled run fireproof consistent under warehouse situation way server Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi MySQL OPPO Reno NVidia macOS