一、使用 yum 安装
- 添加 CentOS 7 Nginx yum 资源库
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
- 安装 nginx
yum -y install nginx
- 启动 nginx
systemctl start nginx
二、测试
- 服务端测试
curl http://localhost
- 客户端测试
配置好防火墙和出站后,在客户端浏览器输入服务器的公网ip
http://192.168.76.101/
三、关键文件位置
rpm包安装的nginx,在总配置文件nginx.conf中通过include的方式,将server块分割出去,成为子配置文件
html 根目录所在位置是:/usr/share/nginx/html/index.html
nginx 配置文件位置: /etc/nginx/nginx.conf
四、rpm包安装的 nginx 常用命令
systemctl start nginx 启动服务
systemctl reload nginx 重新加载nginx.conf配置文件
systemctl restart nginx 重启服务
systemctl stop nginx 停止服务
systemctl enable nginx 开机自启
systemctl disable nginx 开机不自启
systemctl list-unit-files | grep nginx 检查nginx是否已经安装了开机自动启动
systemctl status nginx 查看nginx状态
ps -ef | grep nginx 查看进程nginx进程
netstat -antlp | grep nginx 查看nginx服务端口
yum remove nginx yum 卸载nginx软件包
五、配置开机自启
systemctl enable nginx 开机自启
systemctl disable nginx 开机不自启
网友评论