博客园  :: 首页  :: 管理

关于nginx的源码安装方式

Posted on 2020-05-11 21:32  520_1351  阅读(375)  评论(0编辑  收藏  举报

Nginx(engine x)是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,

也是一个 IMAP/POP3/SMTP 代理服务器。在高连接并发的情况下,Nginx是Apache服务器不错的替代品。

 

操作系统环境: CentOS Linux release 7.7.1908 (Core)

nginx软件版本:nginx-1.18.0.tar.gz

 

1、源码安装前的依赖及准备工作,首先需要创建一个用于管理nginx的worker进度,及安装,编译所需要的开发包依赖

useradd -r -s /sbin/nologin nginx
yum install gcc pcre-devel openssl-devel zlib-devel

2、解压源码包,进入nginx目录,执行源码安装的三步曲操作

[root@localhost ~]# tar zxf nginx-1.18.0.tar.gz 
[root@localhost ~]# cd nginx-1.18.0
[root@localhost nginx-1.18.0]# 
[root@localhost nginx-1.18.0]# ./configure --prefix=/usr/local/nginx \
--user=nginx --group=nginx \
--with-http_ssl_module \
--with-http_v2_module 
[root@localhost nginx-1.18.0]# make && make install 

说明:其中--with-http_v2_module,可选编译项,用于对HTTP_V2的支持,需要有--with-http_ssl_module才有实际的意义

3、安装后的完善工作,可以对nginx二进制程序文件,创建一个软链接到PATH目录,方便在任何目录都可以正常使用nginx命令

4、我们也可以使用systemd的方式、管理nginx,方法如下:

     创建/usr/lib/systemd/system/nginx.service文件,写入如下内容

[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
[Install]
WantedBy=multi-user.target'

这样就可以使用systemctl命令管理nginx了,如重启nginx服务:systemctl restart nginx

将nginx加入开机启动:systemctl enable nginx

 

 

尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/12872066.html