Giter Site home page Giter Site logo

docker-nginx-static's Introduction

Super Lightweight Nginx Image

docker run -v /absolute/path/to/serve:/static -p 8080:80 flashspys/nginx-static

This command exposes an nginx server on port 8080 which serves the folder /absolute/path/to/serve from the host.

The image can only be used for static file serving but has with less than 4 MB roughly 1/10 the size of the official nginx image. The running container needs ~1 MB RAM.

nginx-static via HTTPS

To serve your static files over HTTPS you must use another reverse proxy. We recommend træfik as a lightweight reverse proxy with docker integration. Do not even try to get HTTPS working with this image only, as it does not contain the nginx ssl module.

nginx-static with docker-compose

This is an example entry for a docker-compose.yaml

version: '3'
services:
  example.org:
    image: flashspys/nginx-static
    container_name: example.org
    ports:
      - 8080:80
    volumes: 
      - /path/to/serve:/static

nginx-static with træfik 2.x

To use nginx-static with træfik 2.x add an entry to your services in a docker-compose.yaml. To set up traefik look at this simple example.

In the following example, replace everything contained in <angle brackets> and the domain with your values.

services:
  traefik:
    image: traefik:2.4 # check if there is a newer version
  # Your traefik config.
    ...
  example.org:
    image: flashspys/nginx-static
    container_name: example.org
    expose:
      - 80
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.<router>.rule=Host(`example.org`)"
      - "traefik.http.routers.<router>.entrypoints=<entrypoint>"
# If you want to enable SSL, uncomment the following line.
#      - "traefik.http.routers.<router>.tls.certresolver=<certresolver>"
    volumes: 
      - /host/path/to/serve:/static

If traefik and the nginx-static are in distinct docker-compose.yml files, please make sure that they are in the same network.

For a traefik 1.7 example look at an old version of the readme

nginx-static for multi-stage builds

nginx-static is also suitable for multi-stage builds. This is an example Dockerfile for a static node.js application:

FROM node:alpine
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN npm install && npm run build

FROM flashspys/nginx-static
RUN apk update && apk upgrade
COPY --from=0 /usr/src/app/dist /static

Custom nginx config

In the case you already have your own Dockerfile you can easily adjust the nginx config by adding the following command in your Dockerfile. In case you don't want to create an own Dockerfile you can also add the configuration via volumes, e.g. appending -v /absolute/path/to/custom.conf:/etc/nginx/conf.d/default.conf in the command line or adding the volume in the docker-compose.yaml respectively. This can be used for advanced rewriting rules or adding specific headers and handlers. See the default config here.

FROM flashspys/nginx-static
RUN rm -rf /etc/nginx/conf.d/default.conf
COPY your-custom-nginx.conf /etc/nginx/conf.d/default.conf

docker-nginx-static's People

Contributors

flashspys avatar jorgenpt avatar madhavarshney avatar maxemann96 avatar morbatex avatar msrd0 avatar renovate[bot] avatar schlabbi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

docker-nginx-static's Issues

nginx log

Hello,

I have successfuly deployed my static app as a docker container using this image. However, running sudo docker logs ${my_container} returns no output.

By manually exploring the container, /var/log/nginx/access.log seems to be a link to stdout.

What should I do to get logs?

Push new image ( & Automated build ? )

Would be nice if you would push the latest changes to docker hub.

Also, setting up automated build would be nice. I know docker hub disabled it's free version :(

Getting forbidden error when trying to achieve files

Hi.

I used your image in my docker-compose.yml

my-http-server:
image: flashspys/nginx-static
restart: always
ports:
- 12227:80
volumes:
- /home/my-folder:/static

  • '/home/my-folder' is an absolute path.
  • the container is running,
  • the directory "themes" exists in "/home/my-folder"
  • 'theme' directory also exists inside the container in /static directory

and I am getting the forbidden error.

2020/04/15 18:16:53 [error] 6#6: *1 directory index of "/static/themes/" is forbidden, client: 31.169.202.8, server: localhost, request: "GET /themes/ HTTP/1.1", host: "192.166.123.176:12227"

404 error

Hello, i started using this image with traefik but i keep getting 404 errors on my site and i cant figure why?

Here is my docker-compose file.

services:
  stats:
    image: flashspys/nginx-static
    container_name: stats
    networks:
      
      - web
    expose:
      - 80
    labels:
      - traefik.enable=true
      - traefik.backend=stats
      - traefik.docker.network=web
      - traefik.frontend.rule=Host:stats.io
      - traefik.frontend.headers.STSSeconds=315360000
      - traefik.frontend.headers.STSIncludeSubdomains=true
      - traefik.frontend.headers.STSPreload=true
    volumes: 
      - /staticfiles:/root/dist

'500 Internal Server ErrorServer got itself in trouble'

Hello.

I have small problem with nginx. Now i'm just trying to host few photos for my other services. On browser, everything work nice. But when i try download content to my C# application i get response form fiddler:
userMessage=Downloading image from URL 'http://myDomain.org:Port/FileName.png' failed. Server returned the following HTTP status code: 500 INTERNAL_SERVER_ERROR and response body: '500 Internal Server ErrorServer got itself in trouble'.

Update:
I'm also getting this error:
userMessage=Downloading image from URL 'http://myDomain.org:Port/FileName.png' failed. Server returned the following HTTP status code: 504 GATEWAY_TIMEOUT and response body: 'The remote server timed out'.

I change perrmission of static files chmod 777 without any result.
###########
Traefik
How reach my files from traefik? Without treafik i can reach files through
IP:ExternalPort/StaticFileName

When i configure it with traefik, and my services are configured
Below i show my result of:
curl -s 127.0.0.1:8080/api/rawdata | jq .)

"traefikRouterName@docker": {
  "entryPoints": [
    "web"
  ],
  "service": "traefikServiceName",
  "rule": "Host(`myDomain.org`)",
  "status": "enabled",
  "using": [
    "web"
  ]
},

.

traefikServiceName@docker": {
"loadBalancer": {
"servers": [
{
"url": "http://172.25.0.2:80"
}
],
"passHostHeader": true
},
"status": "enabled",
"usedBy": [
"traefikRouterName@docker"
],
"serverStatus": {
"http://172.25.0.2:80": "UP"
}
},

docker-compose.yml

fileServer:
image: flashspys/nginx-static
container_name: myDomain.org
expose:
- 80/tcp
labels:
- "traefik.enable=true"
- "traefik.http.routers.traefikRouterName.rule=Host(myDomain.org)"
- "traefik.http.routers.traefikRouterName.entrypoints=web"
volumes:
- /absolute/path/to/staticFiles:/static

The url don't work. Is it my mistake?

myDomain.org/staticFileName

Expire Headers ala PageSpeed recommendation

Wouldn't it make sense to add some expire header rules like:

location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to redirecting to index.html
            try_files $uri $uri/ /index.html;
            expires 1w;
            add_header Cache-Control "must-revalidate";
        }

        # Javascript and CSS files
        location ~* \.(?:css|js|json)$ {
            try_files $uri =404;
            expires 1w;
            access_log off;
            add_header Cache-Control "must-revalidate";
        }

        # Media: images, icons, video, audio, HTC
        location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webp|webm|htc|webmanifest)$ {
            expires 1M;
            access_log off;
            add_header Cache-Control "public";
        }

        # Web fonts send expires headers
        location ~* \.(?:eot|otf|ttf|woff|woff2)$ {
          expires 1y;
          access_log off;
          add_header Cache-Control "public";
        }

        # Any route containing a file extension (e.g. /devicesfile.js)
        location ~ ^.+\..+$ {
            try_files $uri =404;
        }

armv7 support

armv7 support is missing.

Tested on Raspberry Pi 3B+ running Raspbian Buster 10

403 When running README command

$ docker run -v out:/static -p 8080:80 flashspys/nginx-static
2020/02/21 09:46:30 [error] 8#8: *1 directory index of "/static/" is forbidden, client: 172.17.0.1, server: localhost, request: "GET / HTTP/1.1", host: "localhost:8080"
2020/02/21 09:46:30 [error] 8#8: *1 open() "/static/favicon.ico" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", host: "localhost:8080", referrer: "http://localhost:8080/"

Going to http://localhost:8080/ throws 403.
Going to http://localhost:8080/index.html throws 404

$ ls out/index.*
out/index.html

This happens when trying to troubleshoot 404 on docker compose.

docker-compose:

version: '3'
services:
  axl:
    image: flashspys/nginx-static
    ports:
      - 8080:80
    volumes:
      # We serve the out folder (relative to the compose file)
      - ../out:/static
  cypress:
    image: 'cypress/included:3.8.3'
    entrypoint: cypress run --project packages/axl
    depends_on:
      - axl
    environment:
      # pass base url to test pointing at the web application
      - CYPRESS_baseUrl=http://axl:80/
      - CYPRESS_snapshots=false
    # share the current folder as volume to avoid copying
    working_dir: /e2e
    volumes:
      # Cypress must run from the folder that has its plugins node_modules
      # Which in the case of this mono-repo is root. So we map the root to the working dir
      - ../../../:/e2e

When up this we get:

axl_1      | 2020/02/20 16:20:22 [error] 7#7: *3 open() "/static/progplus-pools" failed (2: No such file or directory), client: 172.23.0.3, server: localhost, request: "GET /progplus-pools HTTP/1.1", host: "axl"

Upload File to Server

Hi author,

Thank you for creating very good docker-nginx-static for server static contents.

I've tried to upload the files to server. http://0.0.0.0:8000. However, the server throws the 403 error.

Does this image support for uploading the image files ?

Thank you

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

dockerfile
Dockerfile
  • alpine 3.19
github-actions
.github/workflows/main.yml
  • docker/setup-qemu-action v3
  • docker/setup-buildx-action v3
  • docker/login-action v3
  • docker/login-action v3
  • docker/build-push-action v5
  • akhilerm/tag-push-action v2.2.0
regex
Dockerfile
  • library/nginx 1.26.0

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.