[NGINX] How to install NGINX manually on Centos7, simple installation

Installation package

  1. Manual official website download (demo nginx version)

    nginx-1.9.1.tar.gz
    
  2. Use wget to download, centos 7 comes with wget

wget http://nginx.org/download/nginx-1.9.1.tar.gz

insert image description here

Installation Environment

# 安装环境组件
yum -y install make zlib-devel gcc-c++ libtool openssl openssl-devel

Many people, the reason why the installation of nginx is abnormal is that the environment has not been installed in advance. If you don’t understand the installation, it’s ok if you always say yes

Install NGINX

installation manual

Novice Xiaobai, the following content is necessary; prepare to install to [/usr/local] for unified management; if you have your own installation directory, please set it yourself;

#新建 /usr/local/nginx 文件夹
mkdir /usr/local/nginx

#在安装包复制安装包至 安装目录
cp nginx-1.9.1.tar.gz /usr/local/nginx 

#解压安装包
cd  /usr/local/nginx && tar -zxvf nginx-1.9.1.tar.gz

ready to install

#准备安装
cd nginx-1.9.1

#将安装包根据设置的规则配置

#以下命令按着实际安装(二选一)
# 【执行】这个是默认编译,没有https模块
 ./configure 
 
# 【执行】自定义编译,加入https模块 
 ./configure --prefix=/usr/local/nginx --with-http_ssl_module

# 【执行】.... 太多了,请自行按配置文件安装,不一一举例

Compiled
insert image description here

Install

#开始编译安装
make && make install

Successful installation
insert image description here

#上图代表安装成功
#进行清除原有的包即可    
cd /usr/local/nginx && rm -rf nginx-1.9.1*

insert image description hereinsert image description here

common commands

run/restart

#内网端口开放,这里不提示了,正式服务器只需要开放安装组的端口即可
#进入安装目录
cd /usr/local/nginx/
#修改默认配置文件
vim /usr/local/nginx/conf/nginx.conf
#运行nginx
cd /usr/local/nginx/sbin && ./nginx
#查看nginx是否已运行
ps -ef|grep nginx
#nginx重启
cd /usr/local/nginx/sbin && ./nginx -s reload

Set up autostart

#编辑文件 nginx.service
vi /lib/systemd/system/nginx.service

##----------------------输入以下内容-----------------------------##

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target
##----------------------输入以上内容-----------------------------##
# 以上内容描述
#Description:描述服务
#After:描述服务类别
#[Service]服务运行参数的设置
#Type=forking是后台运行的形式
#ExecStart为服务的具体运行命令
#ExecReload为重启命令
#ExecStop为停止命令
#PrivateTmp=True表示给服务分配独立的临时空间
#注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
#[Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3

Save it;

#设置自启
#(启动nginx服务)
systemctl start nginx.service 
#(停止nginx服务)
systemctl stop nginx.service 
#(设置开机自启动)
systemctl enable nginx.service 
#(停止开机自启动)
systemctl disable nginx.service 
#(查看服务当前状态)
systemctl status nginx.service 
#(重新启动服务)
systemctl restart nginx.service 
# (查看所有已启动的服务)
systemctl list-units --type=service

4. The access is successful
. Enter the IP, and the prompt page indicates that the installation is successful.
insert image description here
Here is a mention; if you purchased a cloud server, please check whether port 80 is enabled in the security group of the platform.

Guess you like

Origin blog.csdn.net/qq_1498869403/article/details/130685033
Recommended