本教程将介绍如何一步一步手动编译 OpenResty,OpenResty 是一个基于 Nginx 与 Lua 的高性能 Web 平台,拥有很是好的拓展性让服务器发挥更好性能。教程中将所有依赖 Linux 发行版组建中的依赖,而免除编译带来的后期维护成本。html
我有几张阿里云幸运券分享给你,用券购买或者升级阿里云相应产品会有特惠惊喜哦!把想要买的产品的幸运券都领走吧!快下手,立刻就要抢光了。nginx
OpenResty 的额外拓展:git
OpenSSL 1.0.2,提供 ALPN 支持,支持 HTTP/2github
Nginx-CT,透明证书提升 HTTPS 网站的安全性和浏览器支持浏览器
ngx_PageSpeed,Google 家的网站性能优化工具缓存
Brotli,实现比 Gzip 更高的压缩率安全
Jemalloc,优化内存管理性能优化
学生用户能够在阿里云官网上进行学生认证后购买必定配置的ECS,仅需9.9元每个月,学生用户无需担忧花费过多用在服务器的问题。bash
学生用户在通过学生认证事后就能够在相关网址进行购买,网址为:promotion.aliyun.com/ntms/campus…
买好了服务器就能够去刚刚注册好的帐号管理里的管理控制台去查看服务器以及它的一些配置。服务器
【云计算的1024种玩法】使用 DMS 只要一个浏览器轻松搞定运维任务
【云计算的1024种玩法】ECS和轻量应用服务器的远程控制入门
若是不设置好安全组,到底是没法访问仍是编译失败会分不清的。
须要开放 : 80 和 443 端口
本教程以,Ubuntu 16.04 LTS 64位版 为例。
若是软件版本更新后,为了方便起见,后续修改版本号只需修改下面的变量便可。 在 SSH终端 中输入:
# VersionOpenSSLVersion='openssl-1.0.2l';NginxCTVersion='1.3.2';PageSpeedVersion='1.12.34.2';SystemBit='X64';OpenRestyVersion='openresty-1.11.2.5';复制代码
注: 截止本次更新,OpenResty 1.11.2 版本最高只能搭配 OpenSSL 1.0.2。
上述软件版本更新查看: OpenSSL、Nginx-CT、PageSpeed、OpenResty
更新系统软件源缓存顺便升级组件:
apt updateapt 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 /rootmkdir srccd src复制代码
下载 OpenResty 和其拓展的源代码:
#下载 OpenSSL,Ubuntu 16.04(不包括)如下版本请删除下面的 # 如下载#wget https://www.openssl.org/source/$OpenSSLVersion.tar.gz#tar xzf $OpenSSLVersion.tar.gzwget 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-beta.zip
unzip v$PageSpeedVersion-beta.zip
cd ngx_pagespeed-$PageSpeedVersion-beta/
wget https://dl.google.com/dl/page-speed/psol/$PageSpeedVersion-$SystemBit.tar.gz
tar -xzvf $PageSpeedVersion-$SystemBit.tar.gz
cd ../
wget -c https://openresty.org/download/$OpenRestyVersion.tar.gz
tar zxf $OpenRestyVersion.tar.gz 查看更多复制代码
cd $OpenRestyVersion
./configure --prefix=/usr/local/openresty \
--user=www-data --group=www-data \--add-module=../ngx_brotli \--add-module=../nginx-ct-$NginxCTVersion \--add-module=../ngx_pagespeed-$PageSpeedVersion-beta \--with-http_v2_module \--with-http_ssl_module \--with-http_gzip_static_module \--with-ld-opt='-ljemalloc'make && make install复制代码
Ubuntu 16.04(不包括) 如下版本请在倒数第二行添加:
--with-openssl=../$OpenSSLVersion \复制代码
[ -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 提示页了 pics.mf8.biz/mf8/awxi3.p…