搜索

pdf文档 Centos7安装Nginx或OpenResty

153.82 KB 7 页 4 下载 190 浏览 0 评论 0 收藏
所属分类: 系统运维 / Linux
语言 格式 评分
中文(简体)
.pdf
3
摘要
本文档详细介绍了在 CentOS 7 系统上安装 Nginx 和 OpenResty 的多种方法,包括源码安装和 YUM 安装。内容涵盖安装前依赖环境的配置、下载源代码或 YUM 包、编译安装或直接安装、配置文件路径、程序路径以及启动和重启命令。文档还对比了不同安装方式下的异同点,特别强调了直接调用程序命令和使用 systemctl 管理服务之间的冲突问题,并提供了处理 OpenResty 启动失败时缺少 libssl.so.1.1 依赖的解决方案。
AI总结
# CentOS 7 安装 Nginx 或 OpenResty 总结 ## 一、源码安装 Nginx ### 1. 安装依赖环境 ```bash yum install gcc-c++ gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel ``` ### 2. 下载并编译安装 ```bash wget https://nginx.org/download/nginx-1.18.xx.tar.gz tar -zxf nginx-1.18.xx.tar.gz cd nginx-1.18.xx ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-stream --with-stream_ssl_module make && make install ``` ### 3. 启动与重启 ```bash # 检查配置 ./nginx -t # 启动 ./nginx # 停止 ./nginx -s stop # 退出 ./nginx -s quit # 重新加载 ./nginx -s reload ``` ### 注意事项 - 源码安装的 Nginx 默认未集成到系统服务,需手动管理。 - 可通过创建服务文件或编辑 `/etc/rc.local` 实现开机自启。 ## 二、源码安装 OpenResty ### 1. 安装依赖环境 ```bash yum install gcc-c++ gcc pcre pcre-devel zlib zlib-devel openssl openssl-devel readline-devel curl perl ``` ### 2. 下载并安装 ```bash wget https://openresty.org/download/openresty-1.17.8.1.tar.gz tar -zxf openresty-1.17.8.1.tar.gz cd openresty-1.17.8.1 ./configure --with-http_gzip_static_module --with-stream --with-stream_ssl_module --with-http_realip_module make && make install && make clean ``` ### 3. 启动与重启 ```bash # 检查配置 ./nginx -t # 启动 ./nginx # 停止 ./nginx -s stop # 退出 ./nginx -s quit # 重新加载 ./nginx -s reload ``` ### 注意事项 - OpenResty 的主程序名为 `nginx`,可通过链接 `/usr/local/openresty/bin/openresty` 调用。 - 启动失败时,需安装 `openssl11-libs` 依赖。 ## 三、Yum 安装 Nginx ### 1. 添加 Yum 源 ```bash rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm ``` ### 2. 安装 ```bash yum install nginx ``` ### 3. 启动与管理 ```bash # 启动 systemctl start nginx # 开机自启 systemctl enable nginx # 重新加载 systemctl reload nginx ``` ### 注意事项 - Yum 安装的 Nginx 默认集成到系统服务,推荐使用 `systemctl` 命令管理。 ## 四、Yum 安装 OpenResty ### 1. 添加 Yum 源 ```bash wget https://openresty.org/package/centos/openresty.repo ``` ### 2. 安装 ```bash yum install openresty openresty-resty openresty-opm ``` ### 3. 启动与管理 ```bash # 启动 systemctl start openresty # 开机自启 systemctl enable openresty ``` ### 注意事项 - Yum 安装的 OpenResty 自动集成到系统服务,推荐使用 `systemctl` 命令管理。 ## 五、安装方式异同 | 特性 | Nginx 源码安装 | Nginx Yum 安装 | OpenResty 源码安装 | OpenResty Yum 安装 | |-----------------------|------------------------|------------------------|-------------------------|--------------------------| | 程序路径 | `/usr/local/nginx/sbin/nginx` | `/usr/sbin/nginx` | `/usr/local/openresty/nginx/sbin/nginx` | `/usr/local/openresty/nginx/sbin/nginx` | | 配置文件路径 | `/usr/local/nginx/conf/nginx.conf` | `/etc/nginx/nginx.conf` | `/usr/local/openresty/nginx/conf/nginx.conf` | `/usr/local/openresty/nginx/conf/nginx.conf` | | 是否集成系统服务 | 否 | 是 | 否 | 是 | | 启动方式 | `./nginx` 或脚本自启 | `systemctl` 命令 | `./nginx` 或脚本自启 | `systemctl` 命令 | ## 六、注意事项 - 直接调用 `./nginx` 和 `systemctl` 命令不要混用,避免冲突。 - 启动失败时,可使用 `pkill nginx` 杀死进程后重试。 - 安装指定版本时,可通过 `yum install` 指定包版本。 以上为文档核心内容,总结了 Nginx 和 OpenResty 的四种安装方式及其异同,供快速参考和操作。
P1
P2
P3
P4
P5
P6
P7
下载文档到本地,方便使用
文档评分
请文明评论,理性发言.