yum install -y nginx
通过yum安装的时候提示下面的错误
[root@localhost yum.repos.d]# yum install nginx
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
没有可用软件包 nginx。
错误:无须任何处理
源里面没有的话添加源
默认情况Centos7中无Nginx的源,最近发现Nginx官网提供了Centos的源地址。因此可以如下执行命令添加源:
sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
该命令执行之后,会在/etc/yum.respos.d下面多出一个nginx.repo
安装
sudo yum install -y nginx
安装之后,可以查看nginx的默认安装目录
[root@localhost yum.repos.d]# whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz
[root@localhost yum.repos.d]# pwd
/etc/yum.repos.d
启动Nginx并设置开机自动运行
sudo systemctl start nginx.service
sudo systemctl enable nginx.service
nginx启动:
启动命令:systemctl start nginx
查看程序状态:systemctl status nginx
查看进程:ps aux | grep nginx
停止 systemctl stop nginx
重启 systemctl restart nginx
nginx主要目录:
配置文件:/etc/nginx/nginx.conf
html文件目录:/usr/share/nginx/html/