Nginx Entry Notes ———— configuration file structure

Source: Internet
Author: User
Tags epoll sendfile

Comment Symbol bit in nginx.conf #

The structure of Nginx file, this pair of students just getting started, can look at two more eyes.

The default Config:

#user nobody;worker_processes1; #error_log logs/Error.log, #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid;events {worker_connections1024x768;}    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_timeout0; Keepalive_timeout $;    #gzip on; server {Listen the;        server_name localhost; #charset Koi8-R; #access_log logs/Host.access.log Main; Location/{root HTML;        Index index.html index.htm; } #error_page404/404. html; # REDIRECT Server error pages to theStaticPage/50x.html # Error_page - 502 503 504/50x.html; Location= /50x.html {root html; } # Proxy The PHP scripts to Apache listening on127.0.0.1: the# #location~\.php$ {# Proxy_pass http://127.0.0.1;#} # Pass the PHP scripts to FastCGI server listening on127.0.0.1:9000# #location~\.php$ {# root HTML; # Fastcgi_pass127.0.0.1:9000;        # Fastcgi_index index.php; # Fastcgi_param Script_filename/Scripts$fastcgi_script_name;        # include Fastcgi_params; #} # Deny access to. htaccess files,ifApache's Document Root# concurs with Nginx'S One# #location~ /\.ht {# deny all; #}} # anotherVirtualHostusingMix of ip-, name-, and port-based configuration # #server {# listen8000; # Listen Somename:8080;    # server_name somename alias Another.alias; # Location/{# root HTML;    # index index.html index.htm; #} #} # HTTPS Server # #server {# listen443SSL;    # 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 File Structure:

...              #全局块events {         #events块 ...   } HTTP      #http块 {    ...   #http全局块    Server        #server块    {         ...       #server全局块 location        [PATTERN]   #location块        {            ...        }        Location [PATTERN]         {            ...        }    }    Server    {      ...    }    ...     #http全局块}

1. Global BLOCK: Configure the command that affects Nginx Global. There are usually user groups running Nginx server, nginx process PID storage path, log storage path, configuration file introduction, allow to generate worker process number, etc.

2. Events BLOCK: The configuration affects the Nginx server or the network connection with the user. There are the maximum number of connections per process, which event-driven model is selected to handle connection requests, whether to allow multiple network connections to be accepted at the same time, and to turn on serialization of multiple networks.

3, HTTP block: can be nested multiple servers, configure proxy, cache, log definition and other most functions and the configuration of third-party modules. such as file introduction, Mime-type definition, log customization, whether to use Sendfile transfer file, connection timeout, number of single connection requests, etc.

4, server block: Configure the parameters of the virtual host, an HTTP can have more than one server.

5, location block: Configure the routing of the request, and the processing of various pages.

The following gives you a configuration file, as an understanding, but also into a test machine I set up, give you an example.

########### Each instruction must have a semicolon end.  ################# #user Administrator administrators; #配置用户或者组, the default is nobody nobody. #worker_processes2; #允许生成的进程数, the default is 1#pid/nginx/pid/Nginx.pid; #指定nginx进程运行文件存放地址error_log Log/error.log Debug; #制定日志路径, level. This setting can be put into a global block, an HTTP block, a server block, and a level with this: debug|info|notice|warn|error|crit|alert|emergevents {Accept_mutex on;  #设置网路连接序列化, to prevent the occurrence of surprise group, the default is on Multi_accept on;      #设置一个进程是否同时接受多个网络连接, the default is off #use epoll; #事件驱动模型,Select|poll|kqueue|epoll|resig|/dev/poll|Eventport worker_connections1024x768;   #最大连接数, the default is 512}http {include mime.types; #文件扩展名与文件类型映射表 Default_type Application/octet-stream; #默认文件类型, the default is text/plain #access_log off; #取消服务日志 Log_format MyFormat'$remote _addr– $remote _user [$time _local] $request $status $body _bytes_sent $http _referer $http _user_agent $http _x_ Forwarded_for'; #自定义格式 access_log Log/Access.log MyFormat;   #combined为日志格式的默认值 sendfile on;    #允许sendfile方式传输文件, the default is off, which can be in HTTP blocks, server blocks, and location blocks.  Sendfile_max_chunk 100k;    #每个进程每次调用传输数量不能大于设定的值, the default is 0, that is, there is no upper limit. Keepalive_timeout $;    #连接超时时间, the default is 75s, which can be http,server,location blocks. Upstream Mysvr {server127.0.0.1:7878; Server192.168.10.121:3333backup; #热备} error_page404Https//www.baidu.com; #错误页server {keepalive_requests -; #单连接请求上限次数. Listen4545; #监听端口 server_name127.0.0.1; #监听地址Location~*^.+$ {#请求的url过滤, regular match, ~ is case-sensitive, ~*to be case insensitive.  #root path;  #根目录 #index Vv.txt; #设置默认页 Proxy_pass http://Mysvr; List of servers #请求转向mysvr definedDeny127.0.0.1; #拒绝的ip Allow172.18.5.54; #允许的ip} }}

Above is the basic configuration of Nginx, the following points need to be noted:

1, 1. $remote _addr and $http_x_forwarded_for to record the IP address of the client; 2. $remote _user: Used to record the client user name; 3. $time _local: Used to record access time and time zone; 4.$ Request: The URL and HTTP protocol used to record requests;

5. $status: Used to record the status of the request; 6. $body _bytes_s ent: Record the size of the principal content sent to the client file, 7. $http _referer: Used to record links from that page; 8. $http _user_ Agent: Records information about the client browser;

2, surprise group phenomenon: A network connection arrives, a number of sleep processes are woken up by colleagues, but only one process can get links, which will affect system performance.

3, each instruction must have a semicolon end.

=       starts        with an exact match, such as a request that matches only the end of the root directory, and cannot be followed by any strings. The ^~ begins by indicating that the      URI begins with a regular string, not a regular match ~ that begins with a       case-sensitive regular match, that the ~* begins with a case      -insensitive regular match/      generic match, and that if there is no other match, any request matches to the

Nginx Entry Notes ———— configuration file structure

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.