0%

Overview

nginx supports two kinds of filter when sending response to client, one is header filter, the other is body filter, header filter is called before sending response header to client, body filter is called before sending body to client, you can create your own filter module to do anything(mostly related to header manipulation or body manipulation) without break any nginx source code.

Read more »

Overview

Each connection(preallocated for fast) has two events, one for read, the other for write, after nginx adds connection(fd) EPOLLIN and EPOLLOUT to epoll instance(each worker has its own), when event is ready, call handler saved at proper event in epoll directly, or adds the event in post queue, after epoll quits, at last step call event->handler.

Read more »

Overview

each request is served by a virtual server, then based on uri, select the right location, hence each request has related main_conf, srv_conf, loc_conf that hold config, based on config select proper parameters to process the request.

Read more »

Overview

In nginx, a virtual server is defined by a server block with listen directive inside it, something like this.

1
2
3
4
server {
listen 1.1.1.1:8000;
server_name a.b.com;
}
Read more »

Overview

nginx provides advanced data structure like array, list, queue, rb tree which are specific to nginx, like array, it can grow dynamically, but not support free element back to array, list actually is list of several arrays.

Read more »

Overview

In previous post shared memory tracking, it shows how shared memory is tracked and allocated, but it does not show how to manage allocated shared memory, then provide API for user to use memory from it, say you have a big shared memory, later on you may want to allocate blocks from the shared memory, how does nginx manage the shared memory and allocate block to user quickly? this is the post aims to tell you.

Read more »

Overview

As for shared memory, different processes may allocate memory from it at the same time, so it needs a lock when allocate and free shared memory, nginx provides ngx_shmtx_t which is a combination of spin lock and semaphore, in that lock, first try spin lock, if can’t get the lock, use semaphore to block process.

Read more »

Overview

Shared memory is memory that can be accessed by different processes, as each process’s page table maps to the same physical page, nginx tracks all used shared memory as a list in each cycle. for each shared memory, mmap() is called by master processed after parse conf if same shared memory(same name, name is the key) can’t be reused, otherwise, just copy shared memory address from old cycle to new cycle, save that shared memory address, reused shared memory is not freed during reconfigure, later on fork worker process.

Read more »

Transparent Proxy

Overview

Transparent proxy allows to bind a non-local address(address belong to none interface), so that packet can be sent out with non-local address, meanwhile, with proper iptables and ip rule, incoming packet for transparent socket(non-local dst) can be received properly.

Read more »