推荐使用第二种源码编译安装方式
1. yum安装(无法增加其他模块)
-
安装准备
- 环境配置(centos7)
# 关闭防火墙 systemctl firewalld stop # 关闭selinux getenforce setenforce 0
- 安装准备
# 软件安装 yum -y install gcc gcc-c++ autoconf pcre pcre-devel make automake [可选] yum -y install wget httpd-tools vim # 创建目录 mkdir /opt/nginx cd /opt/nginx mkdir app download logs work backup
-
安装
- 版本区别
Mainline version:开发版
Stable version:稳定版
Legacy versions:历史版本
- 配置yum源
To set up the yum repository for RHEL/CentOS, create the file named /etc/yum.repos.d/nginx.repo with the following contents:
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
gpgcheck=0
enabled=1- 安装
yum list | grep nginx yum -y install nginx nginx -v 查看版本 nginx -V 查看配置参数
-
基本参数
查看:rpm -ql nginx
2. 源码安装(可编译其他模块)
- 下载
官网:http://nginx.org/en/download.html,选择Stable version
# 下载
wget http://nginx.org/download/nginx-1.14.2.tar.gz
# 解压
tar -zxvf nginx-1.14.2.tar.gz
目录结构:
nginx-1.14.2
├── auto 编译时make使用
├── CHANGES change log
├── CHANGES.ru change log
├── conf 配置样例
├── configure 生成中间文件
├── contrib 工具,vim高亮显示:cp -r contrib/vim/* ~/.vim/
├── html 默认html文件
├── LICENSE 证书
├── man 帮助文件
├── README 说明文件
└── src 源代码
- configure
# 查看配置参数
./configure --help | more
# 配置/home/app/nginx
./configure --prefix=/home/app/nginx
生成中间文件在objs下
objs
├── autoconf.err
├── Makefile
├── ngx_auto_config.h
├── ngx_auto_headers.h
├── ngx_modules.c 决定哪些模块会被编译进nginx二进制文件中
└── src
- 编译
# 编译
make
生成编译结果在objs下:
objs
├── autoconf.err
├── Makefile
├── nginx 可执行二进制文件
├── nginx.8
├── ngx_auto_config.h
├── ngx_auto_headers.h
├── ngx_modules.c
├── ngx_modules.o
└── src c编译生成的中间文件
├── core
├── event
├── http
├── mail
├── misc
├── os
└── stream
- 安装(首次安装使用)
make install
安装到配置的路径/home/app/nginx
nginx
├── conf 配置文件
│ ├── fastcgi.conf
│ ├── fastcgi.conf.default
│ ├── fastcgi_params
│ ├── fastcgi_params.default
│ ├── koi-utf
│ ├── koi-win
│ ├── mime.types
│ ├── mime.types.default
│ ├── nginx.conf
│ ├── nginx.conf.default
│ ├── scgi_params
│ ├── scgi_params.default
│ ├── uwsgi_params
│ ├── uwsgi_params.default
│ └── win-utf
├── html 默认页面
│ ├── 50x.html
│ └── index.html
├── logs 日志目录
└── sbin 可执行二进制文件
└── nginx