nginx配置文件了解_了解NGINX配置文件

nginx配置文件了解

It’s very important to understand the structure of the NGINX configuration file to get the best performance from your server. Further, by applying directives on right context in a NGINX configuration will enable you to eliminate repetitive codes and manage your infrastructure better.

了解NGINX配置文件的结构以从服务器中获得最佳性能非常重要。 此外,通过在NGINX配置中的正确上下文中应用指令将使您能够消除重复的代码并更好地管理基础架构。

Therefore to help you understand the structure of the NGINX configuration file, this article will focus on describing the structure of the NGINX configuration file in details.

因此,为了帮助您理解NGINX配置文件的结构,本文将重点介绍NGINX配置文件的详细结构。

什么是Nginx上下文? (What is Nginx Context?)

Let us start with checking the location of the NGINX configuration file. The core configuration file (nginx.conf) can be found in /etc/nginx. The location will vary depending on the installation procedure of NGINX.

让我们开始检查NGINX配置文件的位置。 核心配置文件( nginx.conf )可以在/etc/nginx 。 该位置将根据NGINX的安装过程而有所不同。

Open the core NGINX configuration file in a text editor. The very first thing that you will notice that the configurations are organized in a tree-like structure surrounded by curly braces { and }. These locations surrounded by braces is known as Context for placing configuration directive. Moreover, the configuration directives along with their parameters end with a semicolon.

在文本编辑器中打开核心NGINX配置文件。 首先,您会注意到配置是用花括号{和}包围的树状结构组织的。 用括号括起来的这些位置称为用于放置配置指令的上下文。 此外,配置指令及其参数以分号结尾。

In NGINX, contexts can be nested within other contexts thereby creating a hierarchy. In the following example, the HTTP context declares settings for HTTP protocol. Virtual host settings are declared in the server context and are contained in the http context. Locations contexts that are used to store settings for URLs are contained within a server context.

在NGINX中,上下文可以嵌套在其他上下文中,从而创建层次结构。 在以下示例中,HTTP上下文声明了HTTP协议的设置。 虚拟主机设置在服务器上下文中声明,并包含在http上下文中 。 服务器上下文中包含用于存储URL设置的位置上下文。

# Global context
 ...
 ...
 # http context
http{
     ...
     ...
     # Server context
     server {
              listen 80;
              server_name example.com;
              ...
              ...
              # Location context
              location / {            
                          root /var/www/html;            
                          try_files $uri $uri/ =404;        
                          ...
                          ...
             }
    }
    # Server context
    server {
             ...
             ...
             # Location context
             location / { 
                         ...
                         ...
             }
    }
    ...
    ...
}

NGINX配置文件–主要上下文

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值