1、执行yum命令安装依赖
yum -y install pcre* // 支持正则的pcre模块 yum -y install openssl* // 可以执行交互或批量命令
2、下载
官网地址:http://nginx.org/en/download.html
wget http://nginx.org/download/nginx-1.20.0.tar.gz
3、安装
//通过tar解压安装包 tar -zxvf nginx-1.20.0.tar.gz //进入nginx cd nginx-1.20.0 //执行编译 ./configure //编译报错误的话比如:“C compiler cc is not found”,这个就是缺少编译环境,安装一下就可以了 yum -y install gcc make gcc-c++ openssl-devel //编译成功执行 make && make install
4、测试
//执行 /usr/local/nginx/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
5、启动
./sbin/nginx
查看进程
ps aux|grep nginx
6、浏览器输入ip地址就可以正常访问了
注意:阿里云服务器添加nginx端口号
7、常用命令 (在nginx目录下进行的操作 cd /usr/local/nginx/sbin )
./nginx 启动nginx
./nginx -s stop 快速关闭nginx,可能不保存相关信息,并迅速中止web服务
./nginx -s quit 平稳关闭nginx,保存相关信息,有安排的结束web服务
./nginx -s reload 重启
./nginx -s reopen 重新打开日志文件
8、配置nginx
vim /usr/local/nginx/conf/nginx.conf
配置完成之后,先检测是否有语法错误,再启动nginx
./sbin/nginx -t #检测配置文件 ./sbin/nginx #启动nginx



