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 {
...
}