技术交流QQ群:①185473046   ②190706903   ③203744115   网站地图
登录

下次自动登录
现在的位置: 首页OpenResty>正文
Linux下编译安装OpenResty
2022年06月08日 OpenResty 暂无评论 ⁄ 被围观 4,076次+

OpenResty® 是一款基于 NGINX 和 LuaJIT 的 Web 平台。

官方网站:https://openresty.org/cn/

准备篇

一、防火墙配置

CentOS 8.x默认使用的是firewall作为防火墙,这里改为iptables防火墙。

1、关闭firewall:

systemctl stop firewalld.service #停止firewall

systemctl disable firewalld.service #禁止firewall开机启动

systemctl mask firewalld

systemctl stop firewalld

yum remove firewalld

2、安装iptables防火墙

yum install iptables-services #安装

vi /etc/sysconfig/iptables #编辑防火墙配置文件

# sample configuration for iptables service

# you can edit this manually or use system-config-firewall

# please do not ask us to add additional ports/services to this default configuration

*filter

:INPUT ACCEPT [0:0]

:FORWARD ACCEPT [0:0]

:OUTPUT ACCEPT [0:0]

-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

-A INPUT -p icmp -j ACCEPT

-A INPUT -i lo -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited

-A FORWARD -j REJECT --reject-with icmp-host-prohibited

COMMIT

:wq! #保存退出

systemctl restart iptables.service #最后重启防火墙使配置生效

systemctl enable iptables.service #设置防火墙开机启动

/usr/libexec/iptables/iptables.init restart #重启防火墙

二、关闭SELINUX

vi /etc/selinux/config

#SELINUX=enforcing #注释掉

#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

:wq! #保存退出

setenforce 0 #使配置立即生效

三 、系统约定

软件源代码包存放位置:/usr/local/src

源码包编译安装位置:/usr/local/openresty

四、下载软件包

1、下载openresty

https://openresty.org/download/openresty-1.21.4.1.tar.gz

2、下载pcre(支持openresty伪静态)

http://ftp.cs.stanford.edu/pub/exim/pcre/pcre-8.45.tar.gz

3、下载openssl(openresty扩展)

https://www.openssl.org/source/openssl-1.1.1o.tar.gz

4、下载zlib(openresty扩展)

http://www.zlib.net/zlib-1.2.12.tar.gz

五、安装编译工具及库文件(使用yum命令安装)

yum install apr* autoconf automake bison bzip2 bzip2* cpp curl curl-devel fontconfig fontconfig-devel freetype-devel google-perftools-devel GeoIP-devel git gcc gcc-c++ gd gd-devel gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libunwind-devel libtool* libgomp libxml2 libxml2-devel libXpm* libxml* libXaw-devel libXmu-devel libtiff libtiff* make openssl openssl-devel patch pcre-devel perl php-common php-gd policycoreutils telnet wget zlib-devel ncurses-devel libtirpc-devel gtk* ntpstat bison* sqlite-devel oniguruma libzip-devel

安装篇

安装OpenResty

1、安装pcre

cd /usr/local/src

mkdir /usr/local/pcre

tar zxvf pcre-8.45.tar.gz

cd pcre-8.45

./configure --prefix=/usr/local/pcre

make

make install

2、安装openssl

cd /usr/local/src

mkdir /usr/local/openssl

tar zxvf openssl-1.1.1o.tar.gz

cd openssl-1.1.1o

./config -fPIC shared zlib --prefix=/usr/local/openssl

make

make install

3、安装zlib

cd /usr/local/src

mkdir /usr/local/zlib

tar zxvf zlib-1.2.12.tar.gz

cd zlib-1.2.12

./configure --prefix=/usr/local/zlib

make

make install

4、安装OpenResty

groupadd www

useradd -g www www -s /bin/false

cd /usr/local/src

tar zxvf openresty-1.21.4.1.tar.gz

cd openresty-1.21.4.1

./configure --prefix=/usr/local/openresty --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-http_v2_module --with-luajit --with-pcre-jit --with-http_realip_module --with-http_geoip_module --with-openssl=/usr/local/src/openssl-1.1.1o --with-zlib=/usr/local/src/zlib-1.2.12 --with-pcre=/usr/local/src/pcre-8.45

注意:--with-openssl=/usr/local/src/openssl-1.1.1o --with-zlib=/usr/local/src/zlib-1.2.12 --with-pcre=/usr/local/src/pcre-8.45指向的是源码包解压的路径,而不是安装的路径,否则会报错

gmake

gmake install

#启动OpenResty

/usr/local/openresty/nginx/sbin/nginx

/usr/local/openresty/bin/openresty

#关闭OpenResty

ps -ef | grep nginx

kill -QUIT 1069

kill -TERM 1069

kill -9 nginx

#设置OpenResty开机启动

vi /lib/systemd/system/openresty.service #添加以下代码

[Unit]

Description=The NGINX HTTP and reverse proxy server

After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]

Type=forking

PIDFile=/usr/local/openresty/nginx/logs/nginx.pid

ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t

ExecStart=/usr/local/openresty/nginx/sbin/nginx

ExecReload=/usr/local/openresty/nginx/sbin/nginx -s reload

ExecStop=/bin/kill -s QUIT $MAINPID

ExecStartPost=/bin/sleep 0.1

PrivateTmp=true

[Install]

WantedBy=multi-user.target

:wq! #保存退出

/usr/local/openresty/nginx/sbin/nginx -s stop #停止

systemctl enable openresty.service #设置开机自启动

systemctl start openresty.service #启动

systemctl stop openresty.service #关闭

systemctl restart openresty.service #重启

systemctl reload openresty.service #重新加载配置文件

至此,Linux下编译安装OpenResty完成。

扩展阅读:

OpenResty配置txt、pdf、doc、xls等文件直接下载的方法

在nginx配置文件/usr/local/openresty/nginx/conf/nginx.conf中添加以下代码

location / {

if ($request_filename ~* ^.*?\.(txt|pdf|doc|xls)$){

add_header Content-Disposition: 'attachment;';

}

}

     
» 转载请注明来源:系统运维 » Linux下编译安装OpenResty

  系统运维技术交流QQ群:①185473046 系统运维技术交流□Ⅰ ②190706903 系统运维技术交流™Ⅱ ③203744115 系统运维技术交流™Ⅲ

给我留言

您必须 [ 登录 ] 才能发表留言!



Copyright© 2011-2024 系统运维 All rights reserved
版权声明:本站所有文章均为作者原创内容,如需转载,请注明出处及原文链接
陕ICP备11001040号-3