1、下载nginx
- 下载地址:https://nginx.org/en/download.html
2、把tar包上传到服务器上
3、安装nginx依赖
- 由于nginx是C语言开发,运行时需要下载依赖:pcre、openssl、gcc、zlib
- 命令(使用yum安装):yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
4、解压tar包
- 命令:tar -xvf nginx-1.17.8.tar
5、执行nginx中的configure
- 命令:
- cd nginx-1.17.8
- ./configure
6、解析nginx
- 命令:
- make
- make install
- 执行命令后,会在/usr/local/下会产⽣⼀个nginx⽬录
7、启动nginx
- 命令:
- cd nginx/sbin
- ./nginx
8、验证
-
访问虚拟机ip即可(默认端口为80)
-
如果无法访问则需要关闭防火墙
9、关闭防火墙
- systemctl stop firewalld.service #停止firewall
- systemctl disable firewalld.service #禁止firewall开机启动
10、主要命令
- ./nginx 启动nginx
- ./nginx -s stop 终⽌nginx(当然也可以找到nginx进程号,然后使⽤kill -9 杀掉nginx进程)
- ./nginx -s reload (重新加载nginx.conf配置⽂件)