0

I'm using the latest official nginx docker container.

Whenever I start the container, two files are created in /usr/share/nginx/html

root@ba65db04a18f:/# ls -la /usr/share/nginx/html   
total 16
drwxr-xr-x 2 root root 4096 Jun 28 15:38 .
drwxr-xr-x 3 root root 4096 Jun 23 00:55 ..
-rw-r--r-- 1 root root  537 May 30 13:03 50x.html
-rw-r--r-- 1 root root  612 May 30 13:03 index.html

How do I prevent these files from being created?

The commands I'm using to launch the container are:

docker volume create static
docker run -it --rm --name nginx -v static:/usr/share/nginx/html:ro nginx

The default configuration file (/etc/nginx/nginx.conf) is:

user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
}

And there is one file in /etc/nginx/conf.d called default.conf which has the contents:

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

I've tried overwriting this default.conf file with a blank file by launching the container with the command:

docker volume rm static
docker volume create static
docker run -it --rm --name nginx -v static:/usr/share/nginx/html:ro -v /path/on/host/to/blank/default.conf:/etc/nginx/conf.d/default.conf nginx

But nginx still creates index.html and 50x.html. How do I get it to stop?

  • 3
    Nginx does not create these files. They are in docker image github.com/nginxinc/docker-nginx/blob/master/stable/alpine/… – Alexey Ten Jun 28 '17 at 15:58
  • @AlexeyTen Aha I've been searching for that for hours! So I'll probably have to extend the image and remove them. Dang, I was trying to figure out a way to do it without having to write my own Dockerfile – FGreg Jun 28 '17 at 16:03
1

The nginx docker image is responsible for the index.html and 50x.html files:

https://github.com/nginxinc/docker-nginx/blob/48a4c531fc4bfa80d4270f20a67e2e958856860c/stable/alpine/Dockerfile#L101-L102

To prevent them from being created it would be necessary to extend the official nginx docker image and remove the files.

Alternatively it should also be possible to alter the CMD used to start the container so that it removes the files before starting the nginx process.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.