Nginx安装及基础指令

  |   0 评论   |   0 浏览

Nginx安装及基础指令

1.参考官网进行安装

Linux安装nginx: https://nginx.org/en/linux_packages.html

  1. 安装:yum
yum install yum-utils
  1. 切换目录:
cd /etc/yum.repos.d/
  1. 创建文件:
touch nginx.repo
  1. 修改文件内容:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
  1. Nginx的安装:
yum install nginx

安装完成:我们的版本:nginx.x86_64 1:1.24.0-1.el7.ngx

2.Nginx启动及验证

找到命令目录:

whereis nginx
# nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man8/nginx.8.gz
cd /usr/sbin/

启动命令:

[root@localhost sbin]# ./nginx
[root@localhost sbin]# ps -ef|grep nginx
root      2295  2196  0 07:26 pts/0    00:00:00 vi nginx.repo
root      2855     1  0 09:23 ?        00:00:00 nginx: master process ./nginx
nginx     2856  2855  0 09:23 ?        00:00:00 nginx: worker process
nginx     2857  2855  0 09:23 ?        00:00:00 nginx: worker process
root      2859  2656  0 09:23 pts/1    00:00:00 grep --color=auto nginx

验证nginx本机访问是否成功:

curl localhost:80

如果出现:Welcome to nginx!,证明nginx启动成功。

关闭防火墙:

先查询防火墙的状态:

systemctl status firewalld

关闭防火墙:

systemctl stop firewalld

这样,在宿主机的浏览器中就可以访问了。

开机禁用防火墙:

systemctl disable firewalld

当然也可以指定防火墙开发端口

打开端口: firewall-cmd --permanent --add-port=端口号/协议
关闭端口: firewall-cmd --permanent --remove-port=端口号/协议
重新载入,才能生效 : firewall-cmd --reload
查询端口是否开放: firewall-cmd --query-port=端口/协议

比如,开放111端口

firewall-cmd --permanent --add-port=111/tcp
#success
firewall-cmd --reload
#success

3.Nginx基础指令

查看nginx版本号:在安装目录/usr/sbin/下执行指令

[root@localhost sbin]# ./nginx -v

nginx version: nginx/1.24.0

关闭Nginx命令:

[root@localhost sbin]# ps -ef|grep nginx
root      2295  2196  0 07:26 pts/0    00:00:00 vi nginx.repo
root      2970     1  0 09:43 ?        00:00:00 nginx: master process ./nginx
nginx     2971  2970  0 09:43 ?        00:00:00 nginx: worker process
nginx     2972  2970  0 09:43 ?        00:00:00 nginx: worker process
root      2974  2656  0 09:43 pts/1    00:00:00 grep --color=auto nginx


kill -s QUIT 2970

优雅停止nginx:

/usr/sbin/nginx -s quit
 或者
 /usr/sbin/nginx -s stop

标题:Nginx安装及基础指令
作者:llp
地址:https://llinp.cn/articles/2023/12/15/1702626613465.html