Centos7安装Nginx或OpenResty
153.82 KB
7 页
0 评论
语言 | 格式 | 评分 |
---|---|---|
中文(简体) | .pdf | 3 |
摘要 | ||
本文档详细介绍了在CentOS7系统中安装Nginx和OpenResty的方法,包括源码安装和yum安装两种方式。源码安装Nginx需要先安装编译器和依赖环境如gcc、pcre、zlib和openssl,然后下载并编译源代码包。同样,OpenResty的源码安装也需要类似的准备工作,但还需安装额外的依赖如readline-devel和curl,并使用gmake进行编译。文档还介绍了通过yum仓库安装Nginx和OpenResty的方法,包括添加仓库源文件并安装指定版本。此外,文档比较了不同安装方式下的程序路径、配置文件路径以及系统服务设置,并强调了避免直接使用./nginx命令和systemctl命令混用的重要性。最后,文档还提供了解决启动失败问题的方法,如安装openssl11-libs, 以及如何将Nginx设置为开机自启或创建系统服务。 | ||
AI总结 | ||
《Centos7安装Nginx或OpenResty》摘要:
该文档详细说明了在CentOS7系统中安装Nginx和OpenResty的方法,包括源码安装和yum安装两种方式,并对两种安装方式的异同进行了对比。以下是核心内容的总结:
---
### 一、源码安装Nginx
1. **依赖环境安装**:
- 安装编译器和依赖环境:`gcc-c++`、`pcre`、`zlib`、`openssl`。
- 如:
```bash
# yum install gcc-c++ gcc
# yum install pcre pcre-devel
# yum install zlib zlib-devel
# yum install openssl openssl-devel
```
2. **下载并编译安装**:
- 从官网下载目标版本源代码包:
```bash
# wget -c https://nginx.org/download/nginx-1.18.xx.tar.gz
# tar -xf nginx-1.18.xx.tar.gz
# cd nginx-1.18.xx
```
- 配置并编译安装:
```bash
# ./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
```
- 安装完成后,主程序路径为`/usr/local/nginx/sbin/nginx`,配置文件为`/usr/local/nginx/conf/nginx.conf`。
3. **启动及管理**:
- 检查配置:`./nginx -t`
- 启动:`./nginx`
- 停止/退出:`./nginx -s stop`或`./nginx -s quit`
- 重启:`./nginx -s quit && ./nginx`
- 重新加载配置:`./nginx -s reload`
---
### 二、源码安装OpenResty
1. **依赖环境安装**:
- 与Nginx类似,额外安装`readline-devel`、`curl`、`perl`:
```bash
# yum install readline-devel
# yum install curl perl
```
2. **下载并编译安装**:
- 从官网下载目标版本源代码包:
```bash
# wget -c https://openresty.org/download/openresty-1.17.8.1.tar.gz
# tar -xf openresty-1.17.8.1.tar.gz
# cd openresty-1.17.8.1
```
- 配置并编译安装:
```bash
# ./configure --prefix=/usr/local/openresty \
--with-luajit \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-stream \
--with-stream_ssl_module \
--with-http_realip_module
# gmake && gmake install && gmake clean
```
- 安装完成后,主程序路径为`/usr/local/openresty/nginx/sbin/nginx`,配置文件为`/usr/local/openresty/nginx/conf/nginx.conf`,并创建了一个符号链接`/usr/local/openresty/bin/openresty`。
3. **启动及管理**:
- 启动方式与Nginx类似,支持`./nginx`或`/usr/local/openresty/bin/openresty`命令。
---
### 三、yum安装Nginx
1. **添加Nginx yum源**:
- 下载并安装Nginx.repo:
```bash
# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
```
- 或手动创建 `/etc/yum.repos.d/nginx.repo` 文件。
2. **安装并验证**:
```bash
# yum install nginx
# nginx -v
```
- 主程序路径为`/usr/sbin/nginx`,配置文件为`/etc/nginx/nginx.conf`。
- 默认创建为系统服务,可用`systemctl`管理。
---
### 四、yum安装OpenResty
1. **添加OpenResty yum源**:
- 下载或手动创建 `/etc/yum.repos.d/openresty.repo` 文件:
```bash
# cd /etc/yum.repos.d/
# wget https://openresty.org/package/centos/openresty.repo
```
2. **安装并验证**:
```bash
# yum install openresty
# yum install openresty-resty
# yum install openresty-opm
```
- 主程序路径为`/usr/local/openresty/nginx/sbin/nginx`,配置文件为`/usr/local/openresty/nginx/conf/nginx.conf`。
- 默认创建为系统服务,可用`systemctl`管理。
---
### 五、四种安装方式的异同
1. **程序文件路径**:
- Nginx源码安装:`/usr/local/nginx/sbin/nginx`
- Nginx yum安装:`/usr/sbin/nginx`
- OpenResty源码安装:`/usr/local/openresty/nginx/sbin/nginx`
- OpenResty yum安装:`/usr/local/openresty/nginx/sbin/nginx`,并创建符号链接`/usr/bin/openresty`。
2. **配置文件路径**:
- Nginx源码安装:`/usr/local/nginx/conf/nginx.conf`
- Nginx yum安装:`/etc/nginx/nginx.conf`
- OpenResty源码安装:`/usr/local/openresty/nginx/conf/nginx.conf`
- OpenResty yum安装:`/usr/local/openresty/nginx/conf/nginx.conf`。
3. **系统服务**:
- Nginx源码安装:不创建系统服务,默认不支持`systemctl`管理。
- Nginx yum安装:默认创建系统服务,支持`systemctl`管理。
- OpenResty源码安装:不创建系统服务。
- OpenResty yum安装:默认创建系统服务,支持`systemctl`管理。
4. **注意事项**:
- 直接调用`./nginx`命令和使用`systemctl`命令不要混用,避免冲突。
- 设置开机自启时,只能选择将程序添加到`/etc/rc.local`或创建系统服务中的一种方式。
---
### 六、OpenResty启动失败的解决方案
- 由于OpenResty依赖较高版本的`libssl.so.1.1`,需安装`openssl11-libs`:
```bash
# yum install epel-release
# yum install openssl11-libs
```
---
### 总结
文档详细介绍了Nginx和OpenResty在CentOS7上的安装方法,包括源码安装和yum安装两种方式,并对两种方式的主程序路径、配置文件路径和系统服务特性进行了对比。安装完成后,建议根据需求选择合适的管理方式,避免使用冲突的命令。 |
P1
P2
P3
P4
P5
P6
P7
下载文档到本地,方便使用
文档评分