简体   繁体   中英

Why am I getting this Nginx error about “No such file or directory”?

I am trying to create a local pip2pi repo and then serve it up via Nginx. I have successfully created the repo and have all the wheel files I am wanting on my local machine. They are located like this:

/home/user/code/misc/pip-packs/simple
  \
    ---index.html   
    --- amqp
    \
      -------- index.html
      -------- amqp-1.4.6-py2-none-any.whl
    --- django
    \
      -------- index.html
      -------- Django-1.9.3-py2.py3-none-any.whl
    ... ETC

Now to serve the files I am using Nginx on docker, simply using the official Nginx docker image. I run the container like this:

docker run --name pypi-nginx -p 80:80 \
-v /home/user/code/misc/pip-packs/simple:/usr/share/nginx/html \
-d nginx

I can open localhost and see the index.html at root (/) and I can click on a link eg amqp and then get a link for the amqp-1.4.6-py2-none-any.whl file. When I click on the link I expect a download to initiate. Howver I get a 404 page from Nginx.

THe file is definitely there, as I can run:

docker exec -it pypi-nginx /bin/bash

And then ls and the /usr/share/nginx/html directory and see all the files from the voulume.

Further I can run pip install amqp-1.4.6-py2-none-any.whl on my local, so I know it's an actual wheel file.

Nginx's official log error is:

2016/05/20 14:48:01 [error] 7#7: *1 open() "/usr/share/nginx/html/funcsigs/funcsigs-0.4-py2.py3-none-any.whl" failed (2: No such file or directory), client: 172.17.0.1, server: localhost, request: "GET /funcsigs/funcsigs-0.4-py2.py3-none-any.whl HTTP/1.1", host: "localhost", referrer: "http://localhost/funcsigs/"

but yet it serves the index files in each firectory. The nginx conf files I am using are the standard ones from the container. I can post those if necessary.

In the directory /home/user/code/misc/pip-packs/ is where pip2pi stores the packages it downloaded. So in /home/user/code/misc/pip-packs/ you have

/home/user/code/misc/pip-packs/
\
  --- amqp-1.4.6-py2-none-any.whl
  --- Django-1.9.3-py2.py3-none-any.whl
  --- ETC

Then as in the simple directory as described in the question above, each repo folder supposedly has the wheel file as well, yet there was a 404. Well i glossed over the dir2pi pip-packs/ command, which only created symlinks and did not copy the wheel files. So when I mounted the volume to the container, the actual wheel files, that all the symlinks pointed to, never got copied to the container.

The output of 'ls -al' for the Django folder (packages/simple/django) is:

drwxr-xr-x  2 bdew70 bdew70 4096 May 20 11:02 .
drwxr-xr-x 64 bdew70 bdew70 4096 May 20 11:02 ..
lrwxrwxrwx  1 bdew70 bdew70   39 May 20 11:02 Django-1.9.3-py2.py3-none-any.whl -> ../../Django-1.9.3-py2.py3-none-any.whl
-rwxr-xr-x  1 bdew70 bdew70   88 May 20 11:02 index.html

The solution is to make a Dockerfile and then ADD the wheel files to the /user/share/nginx/ folder along with the html files to the /usr/share/nginx/html/ folder. The Dockerfile should look like this:

FROM nginx
ADD packages/simple /usr/share/nginx/html/
ADD packages /usr/share/nginx

The moral of the story is to use '-al' (or create an alias for ls) when investigating file problems and to be careful of symlinks in Docker container volumes. Especially if the symlink is relative and in the form ../../some-file .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM