0

I'm trying to create a web server to share my test results reports using NGINX.

For this, i'm currently using this docker image.

Inside /usr/share/nginx/html/ of this container, i have:

-mochawesome-report

--assets

--mochawesome.html

-Dockerfile

-nginx.conf

My intention is to browse to localhost:8080/api-results/ and see mochawesome.html.

server {

    listen 80;
    root /usr/share/nginx/html;

    location /api-results/ {
        root /mochawesome-report;
        index mochawesome.html;
    }


}

But unfortunately, it doesn't works:

172.17.0.1 - - [16/May/2018:14:21:24 +0000] "GET /api-results/ HTTP/1.1" 404 572 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36" "-"
2018/05/16 14:21:24 [error] 7#7: *1 "/usr/share/nginx/html/api-results/index.html" is not found (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /api-results/ HTTP/1.1", host: "localhost:8080"

Also, this is my Dockerfile:

FROM nginx:alpine
EXPOSE 80
WORKDIR /usr/share/nginx/html
COPY nginx.conf /etc/nginx/nginx.conf
COPY . /usr/share/nginx/html/
CMD ["/usr/sbin/nginx"]
2
  • can you share your Dockerfile it may shed more light on your problem?
    – Const
    May 16 '18 at 16:32
  • @Const Sure. I've updated my questions. May 16 '18 at 18:02
0

I wonder your site are using relative paths, if it's not working try this:

server {
    listen       8080;
    server_name  mochawesome;

    root   html;
    index  index.html;

    location /xxx {
        proxy_pass http://localhost:8080/mochawesome-report/mochawesome.html;
        sub_filter '<head>' '<head>\n<base href="/mochawesome-report/">';
    }

    location / {
        root /usr/share/nginx/html;
    }
}

It will change the base tag of mochawesome.html, making all requests from the proxied source to work.

0

My intention is to browse to localhost:8080/api-results/ and see mochawesome.html.

There are actually several ways to achieve this, but most similar setup to yours would be:

Files and directory structure on host work directory

.
..
Dockerfile
nginx.conf
api-results/
    mochawesome-resuts/
        ...
    assets
    mochawesome.html

Dockerfile

FROM nginx:alpine
EXPOSE 80
WORKDIR /usr/share/nginx/html
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY api-results /usr/share/nginx/html/api-results

nginx.conf

server {
    listen 80;
    root /usr/share/nginx/html;

    location /api-results {
        root /usr/share/nginx/html;
        index mochawesome.html;
    }
}

Test commands (from host work directory)

docker build . -t test-sf
docker run --rm -it -p 8080:80 --name test-sf test-sf

# navigate in browser to: http://localhost:8080/api-results/

Added benefit is that you are not exposing either Dockerfile or nginx.conf in your html folder. Ofc, this can be refined in number of ways, this is just an answer to your original question.

Just as a working example illustration, below is screenshot from live system, using exactly files, directory structures and commands listed above (printed on screenshot as well).

Working example illustration

3
  • It doesn't works. Pretty much the same problem described above :/ ("/usr/share/nginx/html/mochawesome-report/index.html" is not found) May 17 '18 at 3:47
  • Did you recreate exactly same steps? Since this was posted from working system. Make sure you don't have web server on host interfering.
    – Const
    May 17 '18 at 6:54
  • by "/usr/share/nginx/html/mochawesome-report/index.html" is not found seems like it expects it in html folder not report-api sub-folder. Either adjust root path or move it to that folder and it should work.
    – Const
    May 17 '18 at 8:33

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.