centos7安装OpenResty代替nginx

Mou_icon

centos7安装OpenResty代替nginx

1.安装依赖的软件包

1
yum install readline-devel pcre-devel openssl-devel gcc

2.安装openresty

建立目录:

源代码编译目录: /app/runtimes/openresty

安装执行目录: /app/services/openresty

下载openresty源码:

进入:cd /app/runtimes/openresty

下载:wget https://openresty.org/download/openresty-1.11.2.5.tar.gz

解压:tar -zxvf openresty-1.11.2.5.tar.gz

3.安装LuaJIT

进入:

cd openresty-1.11.2.5/bundle/LuaJIT-2.1-20170808/

清理安装:

make clean && make && make install

4.下载ngx_cache_purge模块,该模块用于清理nginx缓存

1
2
3
4
5
cd ../

wget https://github.com/FRiCKLE/ngx_cache_purge/archive/2.3.tar.gz

tar -xvf 2.3.tar.gz

5.下载nginx_upstream_check_module模块,该模块用于ustream健康检查

1
2
3
wget https://github.com/yaoweibin/nginx_upstream_check_module/archive/v0.3.0.tar.gz

tar -xvf v0.3.0.tar.gz

6.安装openresty

cd /app/runtimes/openresty/openresty-1.11.2.5/

编译:

./configure –prefix=/app/services/openresty –with-http_realip_module –with-pcre –with-luajit –add-module=./bundle/ngx_cache_purge-2.3/ –add-module=./bundle/nginx_upstream_check_module-0.3.0/ -j2

安装:

make && make install

7.添加nginx到服务加入开机启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
vi /lib/systemd/system/nginx.service

[Unit]

Description=nginx

After=network.target



[Service]

Type=forking

ExecStart=/app/services/openresty/nginx/sbin/nginx

ExecReload=/app/services/openresty/nginx/sbin/nginx -s reload

ExecStop=/app/services/openresty/nginx/sbin/nginx -s quit

PrivateTmp=true

[Install]

WantedBy=multi-user.target

8.启动并加入开机启动:

systemctl start nginx.service
systemctl enable nginx.service

9.将nginx加入到环境变量

1
2
3
4
5
6
7
vi /etc/profile,加入

# nginx
export NGINX_HOME=/app/services/openresty/nginx
export PATH=$PATH:$NGINX_HOME/sbin

刷新:source /etc/profile
坚持原创技术分享,您的支持将鼓励我继续创作!