简介:
在CentOS上安装Nginx
安装环境及版本:
系统环境:CentOS Linux release 7.5.1804 (Core)
Nginx版本:使用yum安装
一、预备
如果安装Nginx的话,httpd就没有必要存在,查询是有已经安装了httpd,如果没有就跳过,如果有,则需要删除
查询命令:rpm -qa | grep httpd
删除命令:yum remove httpd*
[root@localhost python3Dir]# rpm -qa | grep httpd
httpd-tools-2.4.6-93.el7.centos.x86_64
httpd-2.4.6-93.el7.centos.x86_64
[root@localhost ~]# yum remove httpd*
Loaded plugins: fastestmirror
Resolving Dependencies
.....................
Removed:
httpd.x86_64 0:2.4.6-93.el7.centos httpd-tools.x86_64 0:2.4.6-93.el7.centos
Dependency Removed:
mod_ssl.x86_64 1:2.4.6-93.el7.centos
Complete!
[root@localhost ~]# rpm -qa | grep httpd
[root@localhost ~]#
二、安装
2.1 安装依赖库
命令1:yum -y install automake autoconf libtool make
命令1:yum -y install gcc gcc-c++
命令1:yum -y install epel*
2.2 安装Nginx
命令: yum -y install nginx
[root@localhost libexec]# yum -y install nginx
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
................
Installed:
nginx.x86_64 1:1.16.1-1.el7
Dependency Installed:
centos-indexhtml.noarch 0:7-9.el7.centos dejavu-fonts-common.noarch 0:2.33-6.el7 dejavu-sans-fonts.noarch 0:2.33-6.el7 fontconfig.x86_64 0:2.13.0-4.3.el7 fontpackages-filesystem.noarch 0:1.44-8.el7
gd.x86_64 0:2.0.35-26.el7 gperftools-libs.x86_64 0:2.6.1-1.el7 nginx-all-modules.noarch 1:1.16.1-1.el7 nginx-filesystem.noarch 1:1.16.1-1.el7 nginx-mod-http-image-filter.x86_64 1:1.16.1-1.el7
nginx-mod-http-perl.x86_64 1:1.16.1-1.el7 nginx-mod-http-xslt-filter.x86_64 1:1.16.1-1.el7 nginx-mod-mail.x86_64 1:1.16.1-1.el7 nginx-mod-stream.x86_64 1:1.16.1-1.el7
Dependency Updated:
freetype.x86_64 0:2.8-14.el7
Complete!
2.3 启停、自启动、状态
启动:systemctl start nginx
停止:systemctl stop nginx
重启:systemctl restart nginx
自启动:systemctl enable nginx
查看状态:systemctl status nginx
[root@localhost libexec]# systemctl start nginx
[root@localhost libexec]# systemctl stop nginx
[root@localhost libexec]# systemctl restart nginx
[root@localhost libexec]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@localhost libexec]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2020-07-02 02:10:07 EDT; 8s ago
Main PID: 32717 (nginx)
CGroup: /system.slice/nginx.service
├─32717 nginx: master process /usr/sbin/nginx
├─32718 nginx: worker process
└─32719 nginx: worker process
Jul 02 02:10:07 localhost.localdomain systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jul 02 02:10:07 localhost.localdomain nginx[32712]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jul 02 02:10:07 localhost.localdomain nginx[32712]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jul 02 02:10:07 localhost.localdomain systemd[1]: Started The nginx HTTP and reverse proxy server.
2.4 配置
具体配置需要结合应用,主要用户集群配置