nginx site config
    server {
    listen 80;
    server_name _;
    server_tokens off;
    gzip_static on;

    location ~* \.(html)$ {
        add_header 'X-XSS-Protection' '1';

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html;

it works perfect with docker image node:14.19.3 (nginx/1.14.2), but with node:14-alpine (nginx/1.22.1) it behaves differently:

  • trying accessing index.html (or /) redirects to default /var/lib/nginx/index.html (renders "Welcome to Nginx!"), though /usr/share/nginx/html/index.html exists and with permissions everything is OK
  • if copy /usr/share/nginx/html/index.html to /usr/share/nginx/html/index.txt - it is opened (http://<<mydomain>/index.txt)
  • if copy /usr/share/nginx/html/index.html to /usr/share/nginx/html/i.html - 404 - not found (http://<<mydomain>/i.html, well, it just can't find it in /var/lib/nginx/i.html)
  • if remove the upper location block from the site config everything works perfect (there is just no that extra response header)
  • 1
    You will have to compare the entire nginx config files (not a single one) from machine to machine to learn what are the differences.
    – Lex Li
    Nov 26, 2022 at 18:51
  • 1
    Run nginx -T on both setups and compare the differences. Nov 26, 2022 at 21:04


You must log in to answer this question.

Browse other questions tagged .