1. 下载nginx

​http://nginx.org/en/download.html​

选择稳定版本即可 Stable version

这里我们选择 nginx-1.14.2

2. 上传nginx到linux上

上传路径为 /usr/local/

3. 解压

tar -xvf nginx-1.14.2.tar.gz

cd nginx-1.14.2

4. 安装依赖

yum install gcc gcc-c++ pcre pcre-devel zlib zlib-devel -y

5. 编译安装

进入nginx源码所在的目录

cd /usr/local/nginx-1.14.2

1)开始配置

./configure --prefix=/opt/soft/nginx-1.14.2 --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_gunzip_module --with-http_sub_module --with-pcre --with-openssl=/usr/local/openssl-1.1.1c

上述命令中的 openssl-1.1.1c是源码包,需要从下面的网站下载:

wget ​​ftp://ftp.openssl.org/source/openssl-1.1.1c.tar.gz​

2)编译

make

3)安装

make install

4)启动

cd /opt/soft/nginx-1.14.0

sbin/nginx

6. nginx 常用命令

nginx -s stop 快速关闭Nginx,可能不保存相关信息,并迅速终止web服务。

nginx -s quit 平稳关闭Nginx,保存相关信息,有安排的结束web服务。

nginx -s reload 因改变了Nginx相关配置,需要重新加载配置而重载。

nginx -s reopen 重新打开日志文件。

nginx -c filename 为 Nginx 指定一个配置文件,来代替缺省的。

nginx -t 不运行,而仅仅测试配置文件。nginx 将检查配置文件的语法的正确性,并尝试打开配置文件中所引用到的文件。

nginx -v 显示 nginx 的版本。

nginx -V 显示 nginx 的版本,编译器版本和配置参数。

7. 几个重要参数说明

–prefix nginx的安装目录,包括配置文件,启动命令等

–with-http_ssl_module 支持HTTPS 需要配合 with-openssl 参数

–with-http_stub_status_module 用于访问基本状态信息

–with-http_gzip_static_module 允许发送扩展名为“.gz”的预压缩文件,而不是常规文件

–with-http_gunzip_module 为不支持“gzip”编码方法的客户端生成用“content encoding:gzip”解压缩响应

–with-http_sub_module 构建通过将一个指定字符串替换为另一个指定字符串来修改响应

–with-pcre 强制使用PCRE库

–with-openssl 见 --with-http_ssl_module