CentOS7 安装 Nginx
在 CentOS 中使用 yum 直接来安装 Nginx的话会出现如下错误,原因是Nginx这个软件不是 yum源中自带的,所以需要手动来配置添加 Nginx 的 yum 源。
[root@centos-linux ~]# yum install nginx
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: ftp.sjtu.edu.cn
* updates: ftp.sjtu.edu.cn
没有可用软件包 nginx。
错误:无须任何处理
添加 yum源:
[root@centos-linux ~]# rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
安装 Nginx:
yum install nginx
已加载插件:fastestmirror
nginx | 2.9 kB 00:00:00
nginx/x86_64/primary_db | 34 kB 00:00:02
Loading mirror speeds from cached hostfile
* base: ftp.sjtu.edu.cn
* extras: ftp.sjtu.edu.cn
* updates: ftp.sjtu.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 nginx.x86_64.1.1.14.0-1.el7_4.ngx 将被 安装
--> 解决依赖关系完成
依赖关系解决
=========================================================================================================================
Package 架构 版本 源 大小
=========================================================================================================================
正在安装:
nginx x86_64 1:1.14.0-1.el7_4.ngx nginx 750 k
事务概要
=========================================================================================================================
安装 1 软件包
总下载量:750 k
安装大小:2.6 M
Is this ok [y/d/N]: y6
Is this ok [y/d/N]: y
Downloading packages:
nginx-1.14.0-1.el7_4.ngx.x86_64.rpm | 750 kB 00:00:41
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
正在安装 : 1:nginx-1.14.0-1.el7_4.ngx.x86_64 1/1
----------------------------------------------------------------------
Thanks for using nginx!
Please find the official documentation for nginx here:
* http://nginx.org/en/docs/
Please subscribe to nginx-announce mailing list to get
the most important news about nginx:
* http://nginx.org/en/support.html
Commercial subscriptions for nginx are available on:
* http://nginx.com/products/
----------------------------------------------------------------------
验证中 : 1:nginx-1.14.0-1.el7_4.ngx.x86_64 1/1
已安装:
nginx.x86_64 1:1.14.0-1.el7_4.ngx
完毕!
查看Nginx的软件包信息:
[root@centos-linux ~]# rpm -ql nginx
/etc/logrotate.d/nginx
/etc/nginx
/etc/nginx/conf.d
/etc/nginx/conf.d/default.conf
/etc/nginx/fastcgi_params
/etc/nginx/koi-utf
/etc/nginx/koi-win
/etc/nginx/mime.types
/etc/nginx/modules
/etc/nginx/nginx.conf
/etc/nginx/scgi_params
/etc/nginx/uwsgi_params
/etc/nginx/win-utf
/etc/sysconfig/nginx
/etc/sysconfig/nginx-debug
/usr/lib/systemd/system/nginx-debug.service
/usr/lib/systemd/system/nginx.service
/usr/lib64/nginx
/usr/lib64/nginx/modules
/usr/libexec/initscripts/legacy-actions/nginx
/usr/libexec/initscripts/legacy-actions/nginx/check-reload
/usr/libexec/initscripts/legacy-actions/nginx/upgrade
/usr/sbin/nginx
/usr/sbin/nginx-debug
/usr/share/doc/nginx-1.14.0
/usr/share/doc/nginx-1.14.0/COPYRIGHT
/usr/share/man/man8/nginx.8.gz
/usr/share/nginx
/usr/share/nginx/html
/usr/share/nginx/html/50x.html
/usr/share/nginx/html/index.html
/var/cache/nginx
/var/log/nginx
Nginx 的简单操作:
关闭防火墙:
systemctl stop firewalld.service
查看 Nginx版本:
nginx -v
启动 Nginx服务:
systemctl start nginx
停止 Nginx服务:
systemctl stop nginx
重启 Nginx 服务:
systemctl restart nginx
查看 Nginx 服务状态:
[root@centos-linux html]# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: active (running) since 一 2018-05-14 07:04:11 CST; 7min ago
Docs: http://nginx.org/en/docs/
Process: 1928 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
Main PID: 1929 (nginx)
CGroup: /system.slice/nginx.service
├─1929 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
└─1930 nginx: worker process
5月 14 07:04:10 centos-linux systemd[1]: Starting nginx - high performance web server...
5月 14 07:04:11 centos-linux systemd[1]: Started nginx - high performance web server.
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 Yang!