☰
centos7安装openresty
2026/10/9 7:16:10 网站建设 项目流程

文章目录

    • 1.解压
    • 2.安装

1.解压

压缩包放在/usr/local,进入此路径解压

tar-zxvfopenresty-1.19.3.1.tar.gz

2.安装

将解压目录更名并进入

mvopenresty-1.19.3.1 openrestycdopenresty

编译安装

./configure&&make&&makeinstall

编译安装过程中有可能会出错,提示:error: the HTTP rewrite module requires the PCRE library或者error: the HTTP cache module requires md5 functions from OpenSSL library,需安装OpenSSL依赖:

#如果缺少PCRE或OpenSSL依赖,用此命令安装yum-yinstallpcre-devel openssl openssl-devel

也可能会出现:ERROR: failed to run command: gmake TARGET_STRIP=@: CCDEBUG=-g XCFLAGS=‘-DLUAJIT_ENABLE_LUA52COMPAT’ CC=cc PREFIX=/usr/local/openresty/luajit…,这时候需要安装C 编译器:

#如果缺少C 编译器(cc),用此命令安装yum-yinstallgcc

环境变量配置nginx或openresty都行


上述两个路径都可以做环境变量路径
编辑profile

vim/etc/profile

末尾加以下配置

#nignxexportNGINX_HOME=/usr/local/openresty/nginx/exportPATH=$PATH:$NGINX_HOME/sbin

配置后不要忘了刷新

source/etc/profile

添加Nginx服务

vim/usr/lib/systemd/system/nginx.service

内容粘贴进去

[Unit]Description=nginxAfter=network.target[Service]Type=forkingExecStart=/usr/local/openresty/bin/openresty-c/usr/local/openresty/nginx/conf/nginx.confExecReload=/usr/local/openresty/bin/openresty-sreloadExecStop=/usr/local/openresty/bin/openresty-squitPrivateTmp=true[Install]WantedBy=multi-user.target


允许自启动并开启redis

systemctlenablenginx systemctl start nginx systemctl status nginx


注意服务名设置的是nginx,如果是openresty,就是systemctl … openresty

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询