How to serve a Static website?

Hi, I'm just a noob learning treafik 2 the hard way.
Following this tutorials:
simple setup
Advanced guide

I was able to setup traefik 2 and portainer.
My next step would be to serve a simple page (files are on /var/www/) using NGINX I did try to create a docker-compose.yml to serve my webiste but I have 403 error. Can you point me in the right direction? tutorial page much appreciated

version: '3'

    image: nginx:latest
    container_name: nginx_website
    restart: unless-stopped
      - no-new-privileges:true
      - proxy
      - /var/www:/data:rw
      - "traefik.enable=true"
      - "traefik.http.routers.nginx.entrypoints=http"
      - "traefik.http.routers.nginx.rule=Host(``)"
      - "traefik.http.routers.nginx-secure.middlewares=secured@file,nc-header"
      - "traefik.http.routers.nginx-secure.entrypoints=https"
      - "traefik.http.routers.nginx-secure.rule=Host(``)"
      - "traefik.http.routers.nginx-secure.tls=true"
      - "traefik.http.routers.nginx-secure.tls.certresolver=http"
      - "traefik.http.routers.nginx-secure.service=traefik"
      - ""
      - ""

    external: true

I suggest you tackle it separately. Firstly make sure that you can compose a nginx container that serves you your simple page directly, (e.g. without "traefik.enable=true") and then when it works try exposing it via traefik.

This way you will make sure to exclude problems due to misconfiguration on nginx.

Hi, thank you for your hint, I commented out all the traefik labels ... no luck

So this indicate that the problem is not with traefik. You need to solve this first.

1 Like

I have the impression that your volume is not well configure within Nginx. Here is a hint.

But yeah, it's not an issue traefik.

Hi, if i did set the volume to

      - /var/www:/srv:rw

I get to the nginx page indeed, but if I save a index.html test file in /var/www I can't serve it and I still see the nginx welcome page. Why?
I small step on the right direction but still along way to go

Try the whole demo from the link I shared above. It will do exactly what your are looking for :slight_smile:

Hi! Although I did run your demo on "Play with Docker" I am not able to run it on my Digital Ocean Ubuntu Docker Droplet is it because I'm not running swarm?
Moreover is there a graphic schema of the components you put together?

Thanks a lot for your help

It looks like your nginx volumes definition may be wrong. On the presumption that the files you want to serve from nginx are in /data outside the container, try changing it to:

- /data:/usr/share/nginx/html:ro

This also makes the files read-only to the nginx container which is a good precaution to take. If this troubles you change that 'ro' back to 'rw'.