nginx配置文件和配置命令详解案例

一.nginx.conf配置结构

1.1配置结构图

在这里插入图片描述

1.2 nginx中配置nginx.conf配置内容

#user  nobody;
user root;  # 表示worker进程是有root用户去执行的
worker_processes  2;
events {
    # 默认使用epoll
    use epoll;
    # 每个worker链接最大数据
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

二. nginx.conf配置详解

2.1 user root; ======>使用worker进行使用root用户去执行
# 表示worker进程是有root用户去执行的
user root;  
worker_processes  2;
events {
    # 默认使用epoll
    use epoll;
    # 每个worker链接最大数据
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
       # ...
    }
}

在这里插入图片描述

2 .2 events ======>配置worker进程最大连接数和worker进程的工作模式配置,可以提供nginx并发数。

在这里插入图片描述

2.3 http ===>>>>>网络相关传输模块配置
http {
    include       mime.types;    #1.导入外部文件
    default_type  application/octet-stream;
    sendfile        on;         #2.打开文件高效传输的,默认是打开的
    #tcp_nopush     on;         #3.这个是需要和sendfile配合一起使用,它的意思是数据包累计到一定大小的时候才发送。
    keepalive_timeout  65;      #4.客户端连接到服务器的超时时间【超过的时间就会关闭,如果有新的客户端连接发现有,没有关闭的连接就会直接使用不要重新连了】
    #gzip     on;               #5.开启后发现css,js等数据,就会就行压缩.
    server {
       listen       80;
       server_name  localhost;
       location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
    #6.导入一个外部的配置文件
    include oa.conf;
}


# oa.conf具体内容如下: >>>>>注意oa.conf和nginx.conf在同一个目录下<<<<
server {
       listen       89;
       server_name  localhost;
       location / {
            root   html;
            index  oa.html index.htm;
       }
}

相关推荐

  1. nginx配置文件详解

    2024-05-11 21:06:06       11 阅读
  2. nginx配置文件详解

    2024-05-11 21:06:06       25 阅读
  3. Nginx配置文件详解与实践

    2024-05-11 21:06:06       9 阅读
  4. Nginx(十四) 配置文件详解 - 负载均衡(超详细

    2024-05-11 21:06:06       40 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-05-11 21:06:06       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-05-11 21:06:06       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-05-11 21:06:06       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-05-11 21:06:06       18 阅读

热门阅读

  1. Linux技能

    2024-05-11 21:06:06       9 阅读
  2. Clickhouse IP 函数

    2024-05-11 21:06:06       10 阅读
  3. python删除一个文件夹所有文件

    2024-05-11 21:06:06       7 阅读
  4. Linux部署安装

    2024-05-11 21:06:06       7 阅读
  5. 在Ubuntu上安装并配置SWAP虚拟内存的完整教程

    2024-05-11 21:06:06       11 阅读
  6. ASP.NET Core SignalR 配置与集成测试究极指南

    2024-05-11 21:06:06       12 阅读
  7. 解决FS4054低耐压批量时不良容易烧,FS4054H高耐压

    2024-05-11 21:06:06       10 阅读
  8. Linux专题-Makefile(2)

    2024-05-11 21:06:06       11 阅读
  9. SpringSecurity安全管理框架-(一)初识SpringSecurity

    2024-05-11 21:06:06       9 阅读