Centos 上通过RPM包安装 Nginx

1. Nginx 安装

yum -y install nginx*

2. Nginx服务管理:

2.1 开机自动启动

systemctl enable nginx

执行结果如下:

systemctl enable nginx

Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

2.2 启动服务

注意在启动服务的时候,要关闭nginx 否则开着nginx ,启动服务就会报错如下

systemctl start nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

[root@ip-172-31-2-29 html]# pkill nginx
[root@ip-172-31-2-29 html]# systemctl start nginx

2.3 重载服务

重载服务有两种方法

方法1:

systemctl reload nginx

方法2:

pkill -HUP nginx

2.4 重启服务

systemctl restart nginx

2.5 关闭服务

关闭服务有两种方法

方法1:

systemctl stop nginx

方法2:

pkill nginx

2.6 Nginx进程管理

Nginx进程管理有两种方法

方法1:

pstree |grep nginx
       
|-nginx---4*[nginx]

方法2:

ps -ef |grep nginx
root      9780     1  0 02:43 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etcnginx/nginx.conf

nginx     9781  9780  0 02:43 ?        00:00:00 nginx: worker process
nginx     9782  9780  0 02:43 ?        00:00:00 nginx: worker process
nginx     9783  9780  0 02:43 ?        00:00:00 
nginx: worker process
nginx     9784  9780  0 02:43 ?        00:00:00 
nginx: worker process
root     11639 17505  0 02:46 pts/3    00:00:00 grep --color=auto nginx
nginx    14115 29744  0 Sep19 ?        00:00:00 php-fpm: pool www
nginx    14116 29744  0 Sep19 ?        00:00:00 php-fpm: pool www
nginx    14117 29744  0 Sep19 ?        00:00:00 php-fpm: pool www

nginx    14118 29744  0 Sep19 ?        00:00:00 php-fpm: pool www
nginx    14119 29744  0 Sep19 ?        00:00:00 php-fpm: pool www

2.7 Nginx端口管理

netstat -tunpl |grep nginx

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      9780/nginx: master 
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      9780/nginx: master