nginx配置文件nginx.conf的结构、各个指令(元素)的含义以及用法

news2024/10/5 17:17:57

nginx配置文件nginx.conf的结构、各个指令(元素)的含义以及用法

  • 默认的nginx.conf
  • nginx.conf配置文件官方解释
  • nginx.conf配置文件中每一条指令或指令快的含义是什么,以及用法(使用范围:应该配置在什么地方)

默认的nginx.conf


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       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  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #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;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}

nginx.conf配置文件官方解释

  • 官方文档地址
    http://nginx.org/en/docs/

  • 进入nginx.conf配置文件官方解释图示:
    在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述
    原文如下:

nginx consists of modules which are controlled by directives specified in the configuration file. 
Directives are divided into simple directives and block directives. A simple directive consists of the 
name and parameters separated by spaces and ends with a semicolon (;). A block directive has the 
same structure as a simple directive, but instead of the semicolon it ends with a set of additional 
instructions surrounded by braces ({ and }). If a block directive can have other directives inside 
braces, it is called a context (examples: events, http, server, and location).
Directives placed in the configuration file outside of any contexts are considered to be in the main 
context. The events and http directives reside in the main context, server in http, and location in 
server.
The rest of a line after the # sign is considered a comment.

简易翻译:

  1. nginx是由多个模块组成的,而这些模块又是由配置文件nginx.conf中的指定的指令所控制的。
  2. 指令可分为简单指令块指令
  3. 简单指令的结构:name+ 空格+参数值+英文分号。 形如这样,worker_processes 1;
    在这里插入图片描述
  4. 块指令由一个或多个简单指令组成,用大括号{}包围起来,如上图。块指令中可以包含其他块指令。
  5. 一个块指令我们也可称其为一个上下文context, 这样的上下文/块指令有:
    events
    http
    server
    location
  6. nginx.conf配置文件中在以上4个(events、http、server、location)上下文之外的配置指令的地方成为 main 上下文。
  7. 以上5个上下文的包含关系如下:在这里插入图片描述
  8. 指令最前面的 井号 “#” 代表注释

nginx.conf配置文件中每一条指令或指令快的含义是什么,以及用法(使用范围:应该配置在什么地方)

见官网: https://nginx.org/en/docs/

这里以指令proxy_pass为例:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
具体的用法如下图:
在这里插入图片描述

proxy_pass的用法还可参考,其他非官方文章:
Nginx反向代理location与proxy_pass配置规则总结

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/503267.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

今年的面试难度有点大....

大家好,最近有不少小伙伴在后台留言,又得准备面试了,不知道从何下手! 不论是跳槽涨薪,还是学习提升!先给自己定一个小目标,然后再朝着目标去努力就完事儿了! 为了帮大家节约时间&a…

Selenium:利用select模块处理下拉框

目录 一、具体问题 二、解决方案 在UI自动化测试中,有时候会遇到页面元素无法定位的问题,包括xpath等方法都无法定位,是因为前端元素被设置为不可见导致。 这篇博客,介绍下如何通过JavaScript修改页面元素属性来定位的方法。。…

2021年科幻美剧和《人月神话》有啥渊源,书中有个小bug你知道吗

DDD领域驱动设计批评文集>> 《软件方法》强化自测题集>> 《软件方法》各章合集>> 《人月神话》1975版和1995版的封面是这样的: 图1 1975版“The Mythical Man-Month”封面 图2 1995版“The Mythical Man-Month”封面 书中第1章“焦油坑&…

【JS每N日一练】【自动化】gitcode创建子项目并导入git

▒ 目录 ▒ 🛫 导读需求 1️⃣ 创建子项目手动操作编写代码 2️⃣ 导入github项目手动操作编写代码 🛬 文章小结📖 参考资料 🛫 导读 需求 github访问时好时不好的,而且克隆代码及其麻烦,经常失败。所以小…

C语言 | 结构体

C语言 | 结构体 文章目录 C语言 | 结构体C语言结构体详解:1.实例(多重嵌套)1-1.定义1-2.初始化 2.结构体2-1、结构体2-1-1、结构体的类型定义:2-1-2、结构体变量的定义:2-1-3、结构体变量的初始化:2-1-4、使用&#xf…

【夜莺(Flashcat)V6监控】1初识夜莺:介绍及部署

简介 夜莺( Nightingale )是一款国产、开源云原生监控分析系统(从 v6 版本开始,尝试转型成为统一观测平台),集数据采集、可视化、监控告警、数据分析于一体。于 2020 年 3 月 20 日,在 github …

这就是阿里巴巴月薪20K+测试岗的面试题吗?让我这个3年的测试工程师看的冷汗直流.....

朋友入职已经两周了,整体工作环境还是非常满意的!所以这次特意抽空给我写出了这份面试题,而我把它分享给伙伴们,面试&入职的经验! 大概是在2月中的时候他告诉我投递了阿里巴巴并且简历已通过,2月23经过…

NPM 包管理器简介

目录 npm 简介 包(Packages) 更新包 版本控制 运行任务 npm 简介 npm 是 Node.js 的标准包管理器。 npm 的快速指南,强大的包管理器是 Node.js 成功的关键。2017 年 1 月,超过 350000 个软件包被报告在 npm 注册表中列出&a…

java中的Servlet对象生命周期以及过滤器监听器

review: Servlet生命周期中的初始化方法: init() , init(config) public void init(ServletConfig config) throws ServletException { this.config config ; init(); } 因此,如果我们需要在初始化时执行一些自定义的操作,那么我…

简单易用又功能强大,来看看Postman接口测试工具怎么用?

一、Postman介绍 Postman官网上这样介绍它:"Manage all of your organizations APIs in Postman, with the industrys most complete API development environment."看的出来Postman是功能强大的API测试的工具 Postman 提供功能强大的 Web API 和 HTTP 请求的调试&a…

【C++】 类练习---封装链表、人物移动

目录 前言 正文 结构体和类的区别 练习1:封装链表 用类封装链表的注意事项 定义一个链表的节点结构 链表类代码 主函数 运行结果 练习2:人物移动 说明 头文件以及宏 人物类 主函数 运行结果 结语 前言 在学完了【C】 类基础汇总&#x…

Java多线程---线程的创建(Thread类的基本使用)

本文主要介绍Java多线程的相关知识, Thread的创建, 常用方法的介绍和使用, 线程状态等. 文章目录 前言 一. 线程和Thread类 1. 线程和Thread类 1.1 Thread类的构造方法 1.2 启用线程的相关方法 2. 创建第一个Java多线程程序 3. 使用Runnable对象创建线程 4. 使用内部类…

【Java笔试强训 31】

🎉🎉🎉点进来你就是我的人了博主主页:🙈🙈🙈戳一戳,欢迎大佬指点! 欢迎志同道合的朋友一起加油喔🤺🤺🤺 目录 一、选择题 二、编程题 🔥美国节日…

数组传参不理解?(数组传参的本质)

在我们编写程序时,经常需要传递参数给函数,其中一种常见的参数类型就是数组。数组作为一种数据结构,可以存储多个相同类型的数据元素,并按照一定的顺序排列。在函数中传递数组参数,可以方便地对数组进行操作处理。但是…

StarCoder - 源代码大模型

StarCoder 是一种在源代码和自然语言文本上训练的语言模型 (LM)。 它的训练数据包含 80 多种不同的编程语言以及从 github 问题和提交以及笔记本中提取的文本。 StarCoder 是在 github 代码上训练的,因此它可以用来执行代码生成。 更准确地说,模型可以完…

手术麻醉系统源码——业务流程介绍

采用计算机和通信技术,实现监护仪、麻醉机、呼吸机、输液泵等设备输出数据的自动采集,采集的数据能够如实准确地反映患者生命体征参数的变化,并实现信息高度共享,根据采集结果,综合其他患者数据,自动生成手…

在springboot项目中配置数据库下划线命名映射为java的驼峰命名时出错

问题 在使用spirngboot集成mybaits的时候,想要开启命名映射,如图配置 # mybatis配置 mybatis:type-aliases-package: com.zhong.springcloud.pojoconfig-location: classpath:mybatis/mybatis-config.xmlmapper-locations: classpath:mybatis/mapper/*…

4年外包出来,5次面试全挂....

我的情况 大概介绍一下个人情况,男,毕业于普通二本院校非计算机专业,18年跨专业入行测试,第一份工作在湖南某软件公司,做了接近4年的外包测试工程师,今年年初,感觉自己不能够再这样下去了&…

深入理解二分类和多分类CrossEntropy Loss和Focal Loss

深入理解二分类和多分类CrossEntropy Loss和Focal Loss 二分类交叉熵 在二分的情况下,模型最后需要预测的结果只有两种情况,对于每个类别我们的预测得到的概率为 p p p和 1 − p 1-p 1−p,此时表达式为( 的 log ⁡ \log log底数…

如何用ChatGP协助你,从品牌角度对产品提出升级建议?

该场景对应的关键词库(19个): 品牌洋葱图思维模型、产品信息、人群、品类、属性、体验、差异化特征、功效、品牌价值主张、目标用户、需求、痛点、爽点、消费者、外观、功能、结构、产品优化建议、产品开发可行性。 提问模板(3个&#xff09…