Prerequisite: The ngx_http_headers_module module needs to be compiled to support header information operations
add_header
means adding custom headers Information is added to the response header. The command is add_header name value [always];, which can be used in http {}, server {}, location {}, if in location {} context.
Only when the response status code is equal to 200 , 201 (1.3.10), 204, 206, 301, 302, 303, 304, 307 (1.1.16, 1.0.13), or 308 (1.13.0). If the always parameter is specified, the header information will Ignore status codes and force return in all responses.
Note: You can declare multiple add_header instructions. If and only if the current block does not have an add_header, the add_header information declared by the superior will be inherited.
For example:
server { add_header a 123; location / { root /path; } location /download/ { add_header b 321; } }
In the above example, when accessing the /download/ route, header information such as b 321 will be returned, and when accessing the / route, the a 123 header information specified by the superior will be returned.
add_trailer
means to add customized header information to the end of the response header. The command is add_trailer name value [always];, which can be used in http {}, server {}, location {}, if in location {} context, only takes effect when the response status code is equal to 200, 201, 206, 301, 302, 303, 307, or 308, if the always parameter is specified , the header information will ignore the status code and be forced to be returned in all responses.
Note: Multiple add_trailer instructions can be declared. If and only if the current block does not have an add_trailer, the add_trailer information declared by the superior will be inherited.
For examples, refer to the add_header example.
expires
Enable or disable, add or modify the "expires" and "cache-control" fields in the response header, the command is expires [modified] time; or expires epoch | max | off; when the response status code is equal to 200, 201 (1.3.10), 204, 206, 301, 302, 303, 304, 307 (1.1.16, 1.0.13), or 308 ( 1.13.0), the time parameter can be positive or negative time. The time in the "expires" field is calculated as the sum of the current time and the time specified in time. If the modified parameter (0.7.0,0.6.32) is used, the time is calculated as the sum of the file modification time and the time specified in the time directive.
In addition, the time of day can be specified using the "@" prefix (0.7.9, 0.6.34): expires @15h30m;
The content of the "cache-control" field depends on the specified The symbol of time:
The time is a negative number - "cache-control: no-cache"
The time is a positive number or 0 - "cache -control: max-age=t" t is the time specified in the command, in seconds
epoch parameter sets "expires" to the value "thu, 01 jan 1970 00: 00:01 gmt", set "cache-control" to "no-cache".
The max parameter sets "expires" to the value "thu, 31 dec 2037 23:55:55 gmt" and "cache-control" to 10 years. The
off parameter disables adding or modifying the "expires" and "cache-control" response header fields.
The last parameter value can contain variables (1.7.9): For example:
map $sent_http_content_type $expires { default off; application/pdf 42d; ~image/ max; } expires $expires;
The above is the detailed content of How to implement Nginx operation response header information. For more information, please follow other related articles on the PHP Chinese website!

The purpose of NGINXUnit is to simplify the deployment and management of web applications. Its advantages include: 1) Supports multiple programming languages, such as Python, PHP, Go, Java and Node.js; 2) Provides dynamic configuration and automatic reloading functions; 3) manages application lifecycle through a unified API; 4) Adopt an asynchronous I/O model to support high concurrency and load balancing.

NGINX started in 2002 and was developed by IgorSysoev to solve the C10k problem. 1.NGINX is a high-performance web server, an event-driven asynchronous architecture, suitable for high concurrency. 2. Provide advanced functions such as reverse proxy, load balancing and caching to improve system performance and reliability. 3. Optimization techniques include adjusting the number of worker processes, enabling Gzip compression, using HTTP/2 and security configuration.

The main architecture difference between NGINX and Apache is that NGINX adopts event-driven, asynchronous non-blocking model, while Apache uses process or thread model. 1) NGINX efficiently handles high-concurrent connections through event loops and I/O multiplexing mechanisms, suitable for static content and reverse proxy. 2) Apache adopts a multi-process or multi-threaded model, which is highly stable but has high resource consumption, and is suitable for scenarios where rich module expansion is required.

NGINX is suitable for handling high concurrent and static content, while Apache is suitable for complex configurations and dynamic content. 1. NGINX efficiently handles concurrent connections, suitable for high-traffic scenarios, but requires additional configuration when processing dynamic content. 2. Apache provides rich modules and flexible configurations, which are suitable for complex needs, but have poor high concurrency performance.

NGINX and Apache each have their own advantages and disadvantages, and the choice should be based on specific needs. 1.NGINX is suitable for high concurrency scenarios because of its asynchronous non-blocking architecture. 2. Apache is suitable for low-concurrency scenarios that require complex configurations, because of its modular design.

NGINXUnit is an open source application server that supports multiple programming languages and provides functions such as dynamic configuration, zero downtime updates and built-in load balancing. 1. Dynamic configuration: You can modify the configuration without restarting. 2. Multilingual support: compatible with Python, Go, Java, PHP, etc. 3. Zero downtime update: Supports application updates that do not interrupt services. 4. Built-in load balancing: Requests can be distributed to multiple application instances.

NGINXUnit is better than ApacheTomcat, Gunicorn and Node.js built-in HTTP servers, suitable for multilingual projects and dynamic configuration requirements. 1) Supports multiple programming languages, 2) Provides dynamic configuration reloading, 3) Built-in load balancing function, suitable for projects that require high scalability and reliability.

NGINXUnit improves application performance and manageability with its modular architecture and dynamic reconfiguration capabilities. 1) Modular design includes master processes, routers and application processes, supporting efficient management and expansion. 2) Dynamic reconfiguration allows seamless update of configuration at runtime, suitable for CI/CD environments. 3) Multilingual support is implemented through dynamic loading of language runtime, improving development flexibility. 4) High performance is achieved through event-driven models and asynchronous I/O, and remains efficient even under high concurrency. 5) Security is improved by isolating application processes and reducing the mutual influence between applications.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6
Visual web development tools

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools
