I have self-compiled nginx 1.9.14 with http2 support:
nginx version: nginx/1.9.14
built by gcc 4.9.2 (Debian 4.9.2-10)
built with OpenSSL 1.0.1k 8 Jan 2015
TLS SNI support enabled
So I have a location = /
block in my config, which should add a header only when the user accesses the root site (https://myserver.example.com/
).
However when I access my server in Firefox the header in the /
location block (which is WhereIAm
) is not added:
Content-Encoding: gzip
Content-Type: text/html
Date: Thu, 21 Apr 2016 07:12:11 GMT
Etag: W/"570bf892-363"
Last-Modified: Mon, 11 Apr 2016 19:18:42 GMT
Server: nginx
Strict-Transport-Security: max-age=15768000; includeSubDomains; preload
X-Content-Type-Options: nosniff
X-Firefox-Spdy: h2
headerend: AtTheEnd
testing: IsTLS
x-something: ALsoAtTheEnd
This is my nginx config:
server {
listen 80;
listen [::]:80;
server_name myserver.example.com;
root /var/www/html;
server_tokens off;
add_header testing IsHTTP;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name myserver.example.com;
root /var/www/html;
server_tokens off;
index index.php index.html index.htm;
# -- TEST BEGIN --
location = /configtest {
#echo "itworks";
add_header itworks configtest;
}
add_header testing IsTLS;
location = / {
add_header WhereIAm Is:/;
}
location /testdir1 {
add_header WhereIAm Is:/testdir1;
}
location = /testdir2 {
add_header WhereIAm Is:/testdir2;
}
# -- TEST END --
# -- PARSER --
location ~ \.php$ {
#location ~ \..*/.*\.php$ {return 404;}
include snippets/fastcgi-php.conf;
#
# # With php5-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php5-fpm:
fastcgi_pass unix:/var/run/php5-fpm.sock;
}
# -- HTTPS --
# certs sent to the client in SERVER HELLO are concatenated in ssl_certificate
ssl_certificate /path/to/my/certificate;
ssl_certificate_key /path/to/my/privatekey;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
# HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload";
# OCSP Stapling ---
# fetch OCSP records from URL in ssl_certificate and cache them
ssl_stapling on;
ssl_stapling_verify on;
## verify chain of trust of OCSP response using Root CA and Intermediate certs
ssl_trusted_certificate /path/to/the/rootandintermediatecerts;
# more headers
add_header X-Something ALsoAtTheEnd;
add_header HeaderEnd AtTheEnd;
add_header X-Content-Type-Options nosniff;
# deny access to Apache config files
location ~ /\.ht {
deny all;
}
}
So in contrast when I access https://myserver.example.com/testdir1/
(and testdir1
is a directory, which exists on my server) it adds the correct header:
Content-Encoding: gzip
Content-Type: text/html
Date: Thu, 21 Apr 2016 07:24:22 GMT
Etag: W/"571538f2-363"
Last-Modified: Mon, 18 Apr 2016 19:43:46 GMT
Server: nginx
X-Firefox-Spdy: h2
whereiam: Is:/testdir1
What's more confusing is when I change the location block to this:
location = / {
echo "ThisIsATest";
add_header WhereIAm Is:/;
}
(I've compiled nginx with the echo-nginx-module
)
Nginx does not only return the test string when accessing it, but it also adds the correct header:
Content-Type: application/octet-stream
Date: Thu, 21 Apr 2016 07:32:01 GMT
Server: nginx
X-Firefox-Spdy: h2
whereiam: Is:/
So what is going on here and how can I get nginx to only add a header when a user accesses /
?
0 Answers