米饭粑 米饭粑
  • 首页
  • 好物推荐
    • 干货分享
    • 好物推荐
    • 免费资源
    • 非专业测评
  • 技术架构
    • Linux
    • HTTPS
    • Windows Server
  • 网站建设
    • 免费资源
    • 建站程序
    • 云建站
    • WordPress
  • 网络服务
    • CDN
    • DNS
    • HTTPS
  • 教程&更多
    • 更多教程
    • 资讯新闻
    • 琐琐碎碎
    • 关于米饭
    • 打赏米饭
  • 友情链接
  • 阿里云Ping
首页 › 技术架构 › Ubuntu 编译安装 OpenResty 及拓展支持

Ubuntu 编译安装 OpenResty 及拓展支持

妙正灰
4年前技术架构
1,701 0 0

介绍

教程修改日期:2017.06.11 Version 1.0-beta

本教程将介绍如何一步一步手动编译 OpenResty,OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,拥有非常好的拓展性让服务器发挥更好性能。教程中将全部依赖 Linux 发行版组建中的依赖,而免除编译带来的后期维护成本。

OpenResty 的额外拓展:

  1. OpenSSL 1.1.0,提供 ALPN 支持,支持 HTTP/2
  2. Nginx-CT,透明证书提高 HTTPS 网站的安全性和浏览器支持
  3. ngx_PageSpeed,Google 家的网站性能优化工具
  4. Brotli,实现比 Gzip 更高的压缩率
  5. Jemalloc,优化内存管理

教程

本教程以,Ubuntu 16.04 LTS 64位版 为例。

设定版本变量

如果软件版本更新后,为了方便起见,后续修改版本号只需修改下面的变量即可。

在 SSH终端 中输入:

# Version
OpenSSLVersion='openssl-1.1.0g';
NginxCTVersion='1.3.2';
PageSpeedVersion='1.12.34.3';
SystemBit='X64';
OpenRestyVersion='openresty-1.13.6.1';

上述软件版本更新查看: OpenSSL、Nginx-CT、PageSpeed、OpenResty

安装依赖

更新系统软件源缓存顺便升级组件:

apt update
apt upgrade -y

安装依赖组件:

apt install build-essential libreadline-dev libncurses5-dev libpcre3 libpcre3-dev libssl-dev zlib1g-dev unzip git perl make libjemalloc1 libjemalloc-dev

下载源码

这里将 OpenResty 所需的源代码均放置在 /root/src 目录下,方便管理。

cd /root
mkdir src
cd src

下载 OpenResty 和其拓展的源代码:


wget https://www.openssl.org/source/$OpenSSLVersion.tar.gz
tar xzf $OpenSSLVersion.tar.gz

#wget https://github.com/grahamedgecombe/nginx-ct/archive/v$NginxCTVersion.tar.gz
#tar xzf v$NginxCTVersion.tar.gz

git clone https://github.com/google/ngx_brotli.git
cd ngx_brotli
git submodule update --init
cd ../

wget https://github.com/pagespeed/ngx_pagespeed/archive/v$PageSpeedVersion-stable.zip
unzip v$PageSpeedVersion-stable.zip
cd ngx_pagespeed-$PageSpeedVersion-stable/
wget https://dl.google.com/dl/page-speed/psol/1.12.34.2-$SystemBit.tar.gz
tar -xzvf 1.12.34.2-$SystemBit.tar.gz
cd ../

wget -c https://openresty.org/download/$OpenRestyVersion.tar.gz
tar zxf $OpenRestyVersion.tar.gz

编译 OpenResty

cd $OpenRestyVersion
./configure --prefix=/usr/local/openresty \
--user=www-data --group=www-data \
--add-module=../ngx_brotli \
--add-module=../ngx_pagespeed-$PageSpeedVersion-stable \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-openssl=../$OpenSSLVersion \
--with-ld-opt='-ljemalloc'

make && make install

设置变量

[ -z "`grep ^'export PATH=' /etc/profile`" ] && echo "export PATH=/usr/local/openresty/nginx/sbin:\$PATH" >> /etc/profile
[ -n "`grep ^'export PATH=' /etc/profile`" -a -z "`grep /usr/local/openresty/ /etc/profile`" ] && sed -i "s@^export PATH=\(.*\)@export PATH=/usr/local/openresty/nginx/sbin:\1@" /etc/profile
. /etc/profile

后面就可以用,nginx -t 检测配置是否正确,nginx -s reload 重载 Nginx 了。

创建相关目录

mkdir /data/wwwlogs/ -p
mkdir /data/wwwroot/default/ -p
cp /usr/local/openresty/nginx/html/index.html /data/wwwroot/default/

设置服务和开机启动

创建 /etc/systemd/system/openresty.service 文件,内容:

cd /etc/systemd/system/
wget https://gist.githubusercontent.com/ivmm/dbf03e6c7970488652878bb8ddc3a775/raw/48436d911d08e57774c759bdb50548dec31dc86f/openresty.service

编辑 /usr/local/openresty/nginx/conf/nginx.conf 文件为:

cd /usr/local/openresty/nginx/conf/
rm nginx.conf -rf
wget https://gist.githubusercontent.com/ivmm/ab81dee184b64036bd4b8d5abe676264/raw/1cbfbc387aa956f6d9afe39d60e2b8c988a10688/nginx.conf

重新加载 systemd 服务,以便它可以找到我们的文件:

systemctl daemon-reload

通过 systemd 重启 OpenResty:

systemctl restart openresty

设置开机启动:

systemctl enable openresty

打开你的服务器 IP,就能看到安装好的 OpenResty 提示页了

Ubuntu 编译安装 OpenResty 及拓展支持-米饭粑

Nginx OpenResty Ubuntu
0
高考结束了,送17届学弟学妹们的礼物
上一篇
使用 cpuminer 浅尝挖矿,朋友圈装逼
下一篇
评论 (0)
再想想
标签
Appnode Brotli CDN CentOS CentOS8 Debian DNS ECC ECS Ghost HTTP2 HTTPS IIS IPV6 Linux LiteSpeed MariaDB MySQL Nginx OLS OpenLiteSpeed OpenResty OSS PageSpeed PHP PHP7 QUIC Redis RHEL RHEL8 SSL TokuDB Ubuntu Windows Server 2016 Wordpress 云服务器 升级 域名 对象存储 微软 数据库 百度 笔记本 阿里云 阿里云ACP
文章归档
关注米饭粑微信公众号
相关文章
在 RHEL8 CentOS8 下构建 LNMP 环境教程
在 RHEL8 和 CentOS8 上安装 Nginx
在 Ubuntu/Debian 下安装 PHP7.3 教程
Nginx 上部署 TLS1.3、Brotli、ECC双证书实践
关于

稻粢穱麦,挐黄梁些,折腾云计算的经验分享和总结。

菜单
首页 教程 好物 关于 链接 打赏
内页链接
米饭粑 米范导航
Copyright © 2011-2021 米饭粑. Designed by nicetheme. 浙ICP备15006212号-1
  • 首页
  • 教程
  • 好物
  • 关于
  • 链接
  • 打赏
热门搜索
  • 402
  • 113
  • 546
  • 548
  • 460
妙正灰
文科屌丝伪IT男一枚.
337 文章
385 评论
367 喜欢
  • 0
  • 0
  • Top