RHEL/CentOS/Rocky/ubuntu配置nginx最新库源

nginx官网

1、官网

http://nginx.org/

在这里插入图片描述
在这里插入图片描述

2、仓库源地址

http://nginx.org/en/linux_packages.html

在这里插入图片描述
RHEL/CentOS/Rocky
在这里插入图片描述
ubuntu
在这里插入图片描述

二、仓库源配置

1、RHEL/CentOS/Rocky

[root@rocky8 ~]# vim /etc/yum.repos.d/nginx.repo
[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
更新缓存
[root@rocky8 ~]# yum clean all ;yum makecache
查看版本
[root@rocky8 ~]# yum list nginx

2、ubuntun

[root@ubuntu2004-160 ~]# curl https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
    | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
[root@ubuntu2004-160 ~]# echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
> http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
>     | sudo tee /etc/apt/sources.list.d/nginx.lis
更新缓存
[root@ubuntu2004-160 ~]#apt update

三、查看

[root@rocky8 ~]# yum -y install nginx
[root@rocky8 ~]# rpm -qa |grep nginx
[root@rocky8 ~]# systemctl enable --now nginx
[root@rocky8 ~]# ps auxf |grep nginx
查看端口
[root@rocky8 ~]# ss -ntlp
[root@rocky8 ~]# rpm -ql nginx
[root@rocky8 ~]# rpm -qc nginx
主配置文件
[root@rocky8 ~]# vim /etc/nginx/nginx.conf
[root@rocky8 ~]# grep -Ev "^ *#|^$" /etc/nginx/nginx.conf
user  nginx;
worker_processes  auto;
error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    keepalive_timeout  65;
    include /etc/nginx/conf.d/*.conf;
}
子配置文件
[root@rocky8 ~]# ls /etc/nginx/conf.d/
default.conf
[root@rocky8 ~]# vim /etc/nginx/conf.d/default.conf 
[root@rocky8 ~]#  grep -Ev "^ *#|^$" /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

#nginx 正在打开文件
[root@rocky86-101 ~]# lsof -c nginx
#显示版本和编译参数
[root@rocky8 ~]# nginx -V
#测试配置文件是否异常
[root@rocky8 ~]# nginx -t
#修改配置文件后,使用
[root@rocky8 ~]# nginx -s reload

四、配置文件

主配置文件结构:四部分

#事件驱动相关的配置
event {
...
}

#http/https 协议相关配置段
http {
...
}

#默认配置文件不包括下面两个块
#mail 协议相关配置段
mail {
...
}
#stream 服务器相关配置段
stream {
...
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值