1.安装nginx的yum源
一台全新安装的CentOS-7-x86_64-Minimal-1810
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.yum安装nginx
yum install -y nginx vim lrzsz
3.启动,停止,查看状态,重启
systemctl start nginx
systemctl stop nginx
systemctl status nginx
systemctl restart nginx
4.关闭firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动
5.设置开机启动
systemctl enable nginx.service
6.静态资源服务器
nginx安装好之后已经配置好了一个静态资源服务器可以通过查看默认配置文件
cd / && find -name nginx.conf
cat /etc/nginx/nginx.conf
cd /etc/nginx/conf.d/
ls
cat default.conf
在nginx.conf最后发现有行 include /etc/nginx/conf.d/*.conf;说明conf.d目录下的所有配置都是有效的,ls发现default.conf 里面就是一个静态资源的虚拟主机
静态资源的根路径为/usr/share/nginx/html,也可以自行修改
只需将图片,html,css,js,txt等文件放到该目录下就可通过http访问了
7.解决权限问题
setenforce 0