OpenResty是一个基于Nginx和Lua的高性能Web平台,下面是在Linux系统上从源码编译安装OpenResty的完整步骤。
首先安装编译OpenResty所需的依赖包:
sudo apt-get update
sudo apt-get install -y build-essential libpcre3-dev libssl-dev perl make git zlib1g-dev
sudo yum install -y gcc make pcre-devel openssl-devel perl git zlib-devel
wget https://openresty.org/download/openresty-<version>.tar.gz
tar -xzvf openresty-<version>.tar.gz
cd openresty-<version>
将<version>
替换为最新的版本号,例如1.21.4.1
。
./configure --prefix=/usr/local/openresty \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre-jit \
--with-threads \
--with-file-aio
常用配置选项说明:
- --prefix
:指定安装目录
- --with-http_ssl_module
:启用SSL支持
- --with-http_v2_module
:启用HTTP/2支持
- --with-pcre-jit
:启用PCRE JIT编译
- --with-threads
:启用线程支持
make -j$(nproc) # 使用所有CPU核心进行编译
sudo make install
为了方便使用,将OpenResty添加到系统PATH中:
echo 'export PATH=/usr/local/openresty/nginx/sbin:$PATH' >> ~/.bashrc
source ~/.bashrc
openresty -v
应该会显示OpenResty的版本信息。
sudo /usr/local/openresty/nginx/sbin/nginx
创建服务文件/etc/systemd/system/openresty.service
:
[Unit]
Description=OpenResty
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecReload=/usr/local/openresty/nginx/sbin/nginx -s reload
ExecStop=/usr/local/openresty/nginx/sbin/nginx -s quit
[Install]
WantedBy=multi-user.target
然后启用服务:
sudo systemctl enable openresty
sudo systemctl start openresty
缺少依赖错误:
端口冲突:
/usr/local/openresty/nginx/conf/nginx.conf
中的监听端口权限问题:
sudo
运行安装命令模块未启用:
--with-xxx-module
选项通过以上步骤,您应该已经成功在Linux系统上编译安装了OpenResty。