Nginx源码编译安装

妖精的绣舞 提交于 2020-09-24 13:27:28

获取Nginx软件包 ==>(文章末尾有脚本一键安装,含获取软件包)

官网网站:http://www.nginx.org/社区版或http://www.nginx.com/企业版

源码编译安装Nginx软件

回顾源码编译三步走:

① ./configure配置

② make编译

③ make install安装

第一步:上传Nginx软件包到Linux服务器端

第二步:联网,安装Nginx软件所需的依赖库

# yum install pcre-devel zlib-devel openssl-devel -y

第三步:对Nginx软件包进行解压缩操作

# tar -xf nginx-1.18.0.tar.gz

第四步:创建一个www账号

# useradd -r -s /sbin/nologin www

第五步:使用./configure对Nginx软件进行配置(对软件安装包进行配置)

# cd nginx-1.18.0
# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module

编译参数说明

参数 作用
–prefix 编译安装到的软件目录
–user worker进程运行用户
–group worker进程运行用户组
–with-http_ssl_module 支持https 需要pcel-devel依赖



第六步:编译与安装Nginx软件

# make && make instal

Nginx目录介绍

目录 作用
conf 配置文件(nginx.conf)
html 网站默认目录(类似apache的htdocs目录)
logs 日志(access.log、error.log)
sbin 可执行文件 [软件的启动 停止 重启等]



原生启动方式:

# sbin/nginx -c /usr/local/nginx/conf/nginx.conf

原生关闭方式:

# sbin/nginx -s stop

原生重启方式:需要停止Nginx服务,相当于先关闭后打开

# sbin/nginx -s stop
# sbin/nginx -c /usr/local/nginx/conf/nginx.conf

原生的热重载(不停止Nginx服务,重载nginx.conf配置文件)

# sbin/nginx -s reload

☆ Nginx服务配置

CentOS7.6 配置:

使用前提,必须先把Nginx停止掉!!!!!!!!

# sbin/nginx -s stop

编写nginx.service脚本,有了这个脚本,我们就可以使用systemctl对其进行控制了

# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=Nginx Web Server
After=network.target
  
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
  
[Install]
WantedBy=multi-user.target

启动Nginx:

# systemctl start nginx

停止Nginx:

# systemctl stop nginx

重载Nginx:

# systemctl reload nginx

开启启动与开机不启动:

# systemctl enable nginx
# systemctl disable nginx

shell脚本安装Nginx

#!/bin/bash

wget http://nginx.org/download/nginx-1.18.0.tar.gz &>/dev/null
sleep 1
tar -xf nginx-1.18.0.tar.gz &>/dev/null
sleep 1
yum -y install gcc
yum -y install gcc-c++
yum -y install make
yum -y install pcre-devel
yum -y install zlib-devel
yum -y install openssl-devel
sleep 1
cd nginx-1.18.0
./configure --prefix=/usr/local/nginx
sleep 1
make && make install
sleep 1
cd /usr/local/nginx
sbin/nginx
ps -ef | grep nginx

















#shell脚本就是命令的堆砌

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!