Using ‘add_header’ directive we can add Response headers.
Syntax: add_header name value [always];
Default: —
Context: http, server, location, if in location
By default ‘add_header’ directive add the headers only if the response code equals 200, 201, 204, 206, 301, 302, 303, 304, 307, or 308.
If you want to set the headers irrespective of response codes, then use the parameter ‘always’.
Example
location = /about{
add_header url "/about";
add_header version "1.23.4";
return 200 "Hello Welcome to NGINX";
}
nginx.conf
events {
}
http {
include mime.types;
# Buffer size for POST submissions
client_body_buffer_size 10K;
client_max_body_size 4m;
# Buffer size for Headers
client_header_buffer_size 1k;
client_body_timeout 60s;
client_header_timeout 60s;
keepalive_timeout 75s;
send_timeout 60s;
server {
listen 9090;
server_name localhost;
location = /about{
add_header url "/about";
add_header version "1.23.4";
return 200 "Hello Welcome to NGINX";
}
location = /not_found{
return 404 "File can't be found";
}
}
}
This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here