(Personal open source) nginx source code annotation

Source: Internet
Author: User
: This article mainly introduces (personal open-source) nginx source code comments. if you are interested in the PHP Tutorial, please refer to it. Address

Https://github.com/langsim/nginx-1.6.2-comment

Introduction

We hope to complete a highly readable nginx source code annotation.

Uncommented content

  1. Spdy-related code, because spdy has been replaced by http2.
  2. Thread-related code, because at least the nginx thread in version 1.6.2 is still in the experimental stage.
  3. Code of other platforms except linux.
  4. Code for event models other than epoll
  5. Code of other compilers except gcc.
  6. Mail-related code.

Degree of completion

  1. Core directory 60%
  2. Event Directory 20%
  3. Http directory 10%
  4. OS directory 80%

Function linked list

  1. Between the http filter module, ngx_http_top_header_filter and ngx_http_top_body_filter form two function linked lists. the Function calling sequence in the linked list is opposite to that in the ngx_modules array of the corresponding module.
  2. In many phases of http request processing, multiple callback functions are available. the calling sequence of callback functions in the same stage is the same as that of the corresponding module in the ngx_modules array.

Logs

Nginx has two log files by default:

  1. Access. log: each http request generates a record in it.
  2. Error. log: some common, error, or debugging logs during nginx running.

Process model

After nginx is started, there may be four process statuses:

  1. Run a single process on the frontend
  2. Single-process daemon mode
  3. One master process, one (or more) worker processes, one (or zero) cachemanager process, and one (or zero) cacheloader process run together at the front end
  4. One master process, one (or more) worker processes, one (or zero) cachemanager process, and one (or zero) cacheloader process run in the daemprocess state.
    • The master process is used to start other processes. after the master process is started, it is used to manage other processes.
    • The woker process is used to process link requests.
    • The cachemanager process is used to clear cache files as required.
    • When the cacheloader process starts, it will index the cache files in the cache directory in the memory, clear the non-conforming cache files, and then exit.
  5. After it is started, send a signal to the main process of running nginx, and then exit.

Switching process running status

  1. Reload)
  2. Hot upgrade executable file

Compile

Nginx is compiled in the same way as common open-source software on the linux platform. it runs./configure & make install. After./configure, you can add your own custom options.

Nginx usage signal

  1. Quickly disable TERM and INT
  2. Close QUIT
  3. HUP restarts smoothly and reloads the configuration file.
  4. USR1 re-opens the log file, which is of great use in log cutting.
  5. USR2 smooth upgrade executable program
  6. WINCH calmly closes the working process

Nginx memory pool

Nginx has two memory pools

  1. Allocate memory pool for memory usage on shared memory
  2. Apply for a memory pool in the general memory to efficiently use the memory.

Computing hash algorithm used by nginx

  1. Crc32
  2. Crc16
  3. Sha1
  4. Murmurhash
  5. Md5

Communication and synchronization of the nignx process

  1. Use of shared memory
  2. Signal
  3. Unix socket

'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
  • '). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script

    The above introduces (personal open-source) nginx source code comments, including the content, hope to be helpful to friends who are interested in PHP tutorials.

    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.