安装nginx服务

yum install epel-release -y
yum install nginx -y
systemctl enable --now nginx.service
systemctl status nginx.service
rpm -ql nginx #检查安装包文件和路径

Nginx安装和主要配置文件详解_nginx

rpm -qi nginx #检查安装包信息

Nginx安装和主要配置文件详解_配置文件解释_02

验证nginx状态

nginx -t

nginx -V

Nginx安装和主要配置文件详解_nginx_03

ps -ef | grep nginx

Nginx安装和主要配置文件详解_nginx_04

配置nginx文件

Nginx的配置⽂文件的组成部分:

主配置⽂文件 nginx.conf,子配置⽂文件 include conf.d/*.conf

cat /etc/nginx/nginx.conf

全局配置

Nginx安装和主要配置文件详解_nginx_05

http配置

user  nginx;
worker_processes auto;
#daemon off; #前台运行Nginx服务,用于测试、docker等环境
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
worker_rlimit_nofile 65536; #所有worker进程能打开的文件数量上限,包括:Nginx的所有连接
worker_priority 19; #设置进程优先级
#worker_cpu_affinity 00000001 00000010; #设置亲联性,防止不同CPU核心上来回跳转
#master_process off; #测试环境要求单线程

#事件驱动配置
events {
worker_connections 65535; #单个进程最大并发,性能上最好做压力测试看是否满足并发
use epoll; #使用epoll事件驱动
accept_mutex on; #on为轮询,避免惊群
multi_accept on; #默认关闭建议打开,每个工作进程可以同时接受多个新的网络连接
}

#http/https协议相关配置
http {
upstream webserver { #webserver自定义名字
server 172.16.10.8:80;
server 172.16.10.9:80;
}
include /etc/nginx/mime.types; #支持各类文件后缀
default_type application/octet-stream;
proxy_cache_path /etc/nginx/data/nginx/proxycache levels=1:1:1 keys_znotallow=proxycache:20m inactive=120s max_size=1g; #开启缓存
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;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

include /etc/nginx/conf.d/*.conf; #多web服务,以便内容不堆积在这个文件内
}

#stream服务器配置相关段
stream {

}