Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Explain in detail the two methods of compiling and installing Nginx and yum building Nginx under Centos7

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Nginx is indeed better than apache in terms of concurrency and load capacity, and most websites are based on Nginx.

Let's introduce the construction of Nginx.

One source code to install nginx

Install Nginx first, but there is only apache in the local yum repository, not Nginx, which requires manual installation.

The official download website of Nginx is that this http://nginx.org/en/download.html first downloads the tar package locally and uploads it to linux.

Before this, you need to install the corresponding toolkits such as gcc gcc++ make

Yum-y install gcc gcc-c++ make perl pcre-devel zlib-devel

You also need to create a Nginx process user

[root@lin3031] # useradd-M-s / sbin/nologin nginx

1. Decompression

[root@lin3031 ~] # ll

-rw-r--r-- 1 root root 994802 November 12 09:00 nginx-1.13.9.tar.gz

[root@lin3031 ~] # tar xf nginx-1.13.9.tar.gz

[root@lin3031 ~] # ls

Nginx-1.13.9 nginx-1.13.9.tar.gz

2. Statistical module

Enter the decompressed folder

[root@lin3031 nginx-1.13.9] #. / configure\

>-- prefix=/usr/local/nginx\

>-- user=nginx\

>-- group=nginx\

>-- with-http_stub_status_module

Prefix # specify installation location

User=nginx # specify nginx system user

Group=nginx # specify a group

With-http_stub_status_module # add log statistics module

3After confirmation, you can make & & make install

[root@lin3031 nginx-1.13.9] # make & & make install

4 optimize the path

[root@lin3031 nginx-1.13.9] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/

5 Nginx operation control

(1) check syntax

Nginx-t # tests whether the configuration has syntax errors

(2) start and shut down Nginx service

Nginx / / start the service

Killall-1 nginx / / secure restart

Killall-3 nginx / / stop service

(3) Edit Nginx service script

Vi / etc/init.d/nginx

#! / bin/bash

# chkconfig: 35 99 20

# description: Nginx Service Control Script

PROG= "/ usr/local/nginx/sbin/nginx"

PIDF= "/ usr/local/nginx/logs/nginx.pid"

Case "$1" in

Start)

$PROG

Stop)

Kill-s QUIT $(cat $PIDF)

Restart)

$0 stop

$0 start

Reload)

Kill-s HUP $(cat $PIDF)

*)

Echo "Usage: $0 {start | stop | restart | reload}"

Exit 1

Esac

Exit 0

[root@lin3031 nginx-1.13.9] # chmod + x / etc/init.d/nginx

[root@lin3031 nginx-1.13.9] # chkconfig-- add nginx

6 Edit the main configuration file

[root@lin3031 nginx-1.13.9] # vim / usr/local/nginx/conf/nginx.conf

Modify the log enabled by administrative users

Define the log format and remove the previous #

Configure statistics module

Save exit and check the configuration file

7 restart the Nginx service

[root@lin3031 nginx-1.13.9] # systemctl restart nginx

The default web page location for source code installation is / usr/local/nginx/html, which can be modified as needed.

When you come to this source code to install Nginx, it is over.

II. Install Nginx for yum

As you can see, although you can customize the parameters using the source installation, it is too complex compared to the novice, so you need to install it with one click of yum.

Since there is no Nginx in Centos7's local yum repository, you need to switch the yum source to the network source to download and install.

What I use here is Ali Source.

Cd / etc/yum.repos.d

Mv CentOS-Base.repo CentOS-Base.repo.bak # back up the previous official source first

Get Ali source

Wget-O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

Wget-O / etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

Clean up previous warehouse information

[root@localhost yum.repos.d] # yum clean all

Retrieve the list of warehouses

[root@localhost yum.repos.d] # yum list

Now you can install Nginx!

[root@localhost yum.repos.d] # yum-y install nginx

The main configuration file for Nginx is in / etc/nginx/nginx.conf

The default location of the web page is / usr/share/nginx/html

Start

[root@localhost ~] # systemctl start nginx

Restart

[root@localhost ~] # systemctl restart nginx

Stop it

[root@localhost ~] # systemctl stop nginx

Modify the configuration file as required

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report