相关链接

官网:http://nginx.org/

下载页:http://nginx.org/en/download.html

本文所用1.16版本链接:http://45.252.224.80/files/B21100000DD4301F/nginx.org/download/nginx-1.16.0.tar.gz

configure配置项列表:http://nginx.org/en/docs/configure.html

步骤

安装依赖

yum install gcc gcc-c++ autoconf make automake pcre pcre-devel zlib openssl openssl-devel
(其中openssl可根据需要决定是否安装,用来支持开启ssl,也就是https服务)

开放端口(http 80,https 443)

firewall-cmd –zone=public –add-port=80/tcp –permanent
firewall-cmd –zone=public –add-port=443/tcp –permanent

编译

1、下载源代码
首先进入保存源文件的目录
例如lz我要放在/root/soft

cd /root/soft
wget http://nginx.org/download/nginx-1.16.0.tar.gz

2、解压并进入解压目录
tar zxvf nginx-1.16.0.tar.gz
cd nginx-1.16.0

3、configure配置与环境检查

这一步需要参考文章开头提供的配置项列表页面,来决定是否开启某些模块,以及一些其他配置。如果只是开启普通http服务,那么只需要指定安装目录即可

示例:安装到/usr/local/nginx,且开启https服务(需要openssl的支持)
./configure –prefix=/usr/local/nginx –with-http_ssl_module

4、configure通过,执行make && make install 开始编译
如果configure未通过,请根据报错信息解决问题。一般来讲,未通过的原因大部分是缺少依赖。比如你开启了ssl模块,但是系统中却没有openssl,那么肯定会提示需要openssl组件

5、
建立主程序环境变量软连接,方便调用
ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx
开启服务
nginx

访问服务器ip,得到welcome,安装完成~

附nginx常用命令

nginx 启动
nginx -s quit 停止,会在请求完成后杀死worker进程
nginx -s reload 重新启动(改变配置后需要重启生效)
nginx -v 查看版本
nginx -t 检查配置文件
nginx -V 详情信息,包括编译的参数