### 一:安装依赖
yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel open openssl-devel
二:下载nginx稳定版
wget http://nginx.org/download/nginx-1.16.1.tar.gz
三:解压--编译--安装
tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1/
#配置vim,使其语法高亮
mkdir .vim #自己创建一个.vim目录
cp -r contrib/vim/* ~/.vim/
#查看编译参数
./configure --help | more
#编译
./configure --prefix=/usr/local/nginx
#安装:
make && make install
#去prefix指定的目录下
cd /usr/local/nginx/
[root@iZwz95n2hxcdh4x6vicjmgZ nginx]# ls -l
total 16
drwxr-xr-x 2 root root 4096 Jul 9 13:37 conf
drwxr-xr-x 2 root root 4096 Jul 9 13:37 html
drwxr-xr-x 2 root root 4096 Jul 9 13:37 logs
drwxr-xr-x 2 root root 4096 Jul 9 13:37 sbin
#nginx服务器的主程序
[root@localhost sbin]# ls /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx
四:开放linux对外访问的端口号80
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
五:nginx服务的启动操作
1:默认配置文件启动
cd /usr/local/nginx/sbin
./nginx
指定配置文件启动
[root@iZwz95n2hxcdh4x6vicjmgZ sbin]# ./nginx -c /usr/local/nginx/conf/nginx.conf
2:查看帮助信息
./ngxin =h #查看帮助信息
#可以找安装时候的配置
[root@iZwz95n2hxcdh4x6vicjmgZ sbin]# ./nginx -V
nginx version: nginx/1.16.1
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
configure arguments: --prefix=/usr/local/nginx
3:-t 检查配置文件是否正确
[root@iZwz95n2hxcdh4x6vicjmgZ sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
六:验证
http://阿里云公网ip/
七:nginx停服务
cd /usr/local/nginx/sbin
./nginx -s stop