nginx配置文件注释说明

nginx.conf配置文件说明

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# 运行 Nginx 服务的用户和用户组
user  nginx;
# 自动根据 CPU 核心数设置工作进程数
worker_processes  auto;

# 错误日志路径和日志级别(notice 表示记录通知级别及以上的日志)
error_log  /var/log/nginx/error.log notice;
# Nginx 进程 ID 存储文件路径
pid        /run/nginx.pid;


# 事件模块配置,处理客户端连接
events {
    # 每个工作进程允许的最大并发连接数
    worker_connections  1024;
}

# HTTP 核心模块配置,处理 HTTP 请求
http {
    # 包含 MIME 类型映射文件,用于识别不同文件类型
    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;
    # 启用 TCP_NOPUSH 选项,提高网络数据包发送效率(默认注释掉)
    #tcp_nopush     on;

    # 保持长连接的超时时间
    keepalive_timeout  65;

    # 启用 Gzip 压缩(默认注释掉,可根据需要启用)
    #gzip  on;

    # 包含所有 .conf 后缀的配置文件,用于模块化管理,server模块,多个server多个配置文件
    include /etc/nginx/conf.d/*.conf;

    # 定义后端服务器集群,用于负载均衡
    upstream backend {
        # 指定后端服务器地址和端口
        server 192.168.11.3:4321;
    }
}

server配置文件

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# HTTP 服务器配置块,监听 80 端口的所有请求
server {
    # 监听 IPv4 的 80 端口
    listen       9990;
    # 监听 IPv6 的 80 端口
    listen  [::]:9990;
    # 服务器名称,可匹配域名或 IP
    server_name  localhost;

    # 访问日志配置(默认注释掉,不记录访问日志)
    #access_log  /var/log/nginx/host.access.log  main;

    # 根路径请求处理,转发到后端服务器集群
    location / {
        # 将所有请求代理到 upstream 定义的 backend 服务器组
        proxy_pass https://backend;

        # 如果后端是自签名证书,需要禁用 SSL 验证(仅测试环境)
        proxy_ssl_verify off;
    }

    # 404 错误页面配置(默认注释掉,使用默认错误页)
    #error_page  404              /404.html;

    # 服务器错误页面配置,将 500-504 错误重定向到静态页面
    error_page   500 502 503 504  /50x.html;
    # 匹配精确路径 /50x.html 的请求
    location = /50x.html {
        # 指定错误页面的根目录
        root   /usr/share/nginx/html;
    }

    # PHP 脚本代理到 Apache 服务器的配置示例(默认注释掉)
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # PHP 脚本通过 FastCGI 处理的配置示例(默认注释掉)
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # 禁止访问 .htaccess 文件的配置示例(默认注释掉)
    # 如果 Nginx 和 Apache 共用文档根目录,可启用此配置
    #location ~ /\.ht {
    #    deny  all;
    #}
}
使用 Hugo 构建
主题 StackJimmy 设计