Home  >  Article  >  Backend Development  >  NGINX basic modules and configuration

NGINX basic modules and configuration

WBOY
WBOYOriginal
2016-08-08 09:30:10942browse

1. NGINX built-in basic modules

1. NGINX kernel module

2. EVENTS module

3, HTTP core module

2. NGINX basic configuration file

#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;
        }

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

3. NGINX kernel module

#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;

This module Used to control the basic functions of the NGINX server

3. EVENT module

events {
    worker_connections  1024;
}

This module is mainly used to control how NGINX handles connections. Some command parameters of this module will have an important impact on the performance of the application, so you need to be careful when setting it up.

4. HTTP core module

http {
   ...
}

This module implements the processing function of NGINX server for HTTP services. This may be the module that ordinary developers deal with the most
1. Basic instructions
http {
    server {
        ...
    }
}

server: used Configure a virtual host. An http code segment can contain multiple server instructions to configure multiple virtual hosts

http {
    upstream mysvr {
        server 192.168.8.1x:80 weight=5;
        server 192.168.8.2x:80  weight=1;
        server 192.168.8.3x:80  weight=6;
    }
    
    server {
        ...
        location / {
            proxy_pass http://mysvr
        }
        ...   
    }
}

upstream: NGINX load balancing

2. How NGINX chooses a SERVER virtual host

HTTP requests that NGINX will enter The header is compared with each server section in the NGINX configuration file, and the first matched server section is selected. The matching process is processed as follows:

1. Full domain name, static domain name matching

2. Use wildcards in the beginning part Domain names, such as: *.xxx.com

3, domain names with wildcard characters at the end, such as: www.xxx.*

4, domain names with regular expressions

If no matching domain name is found, continue Select a server in the configuration file in the following order:

1. The section marked [default|default_server] that matches the listen directive

2. The first server that matches the listen directive (or implies listen 80) Section

The above has introduced the basic modules and configuration of NGINX, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:magic method in phpNext article:magic method in php