The only catch is that you need to mount the directory ahead of time, otherwise the access will always be 404…

Docker installs nginx and uses custom configuration files

I have a requirement today, that is, I need to set up a download interface for the uploaded files, which took a long time. When I used the interface to download, the file downloaded by the browser was always Response. bin, but Baidu did not find the problem, I am also convinced, I really don’t know where the configuration is wrong.

Miraculously, response.bin is the file downloaded by the target. I changed the suffix to the suffix of the original file and found that it is the same file…

In the end, security was abandoned and nginx was used to configure static resource files and download files directly. The disadvantages of this is that you can’t control security flexibly. If the link is leaked, then anyone can access the resource.

Default. conf is modified as follows:

Since the project file is uploaded to the server’s: /opt/upload folder, this absolute path is used for URL mapping.

First, you need to make sure that the path for storing static resources actually exists in the nginx image and is mapped to the corresponding folder on the host machine.

Here alias specifies the alias that maps to the real path of the server, without double quotation marks. I put double quotation marks in the beginning, but it never worked.

If the nginx image is already running, manually create the folder inside the image and restart the image. You need to map and mount the directory when starting the image for the first time.

So if you start the nginx mirror command, it becomes:

  docker run --privileged=true \
  --restart=always \
  --name nginx \
  -d -p 80:80 \
  -v /usr/soft/nginx/html:/usr/share/nginx/html \
  -v /usr/soft/nginx/nginx.conf:/etc/nginx/nginx.conf:ro \
  -v /usr/soft/nginx/conf.d:/etc/nginx/conf.d \
  -v /opt/upload:/opt/upload \
  192.168104.51.:5000/huaun/nginx:test
Copy the code

Among them

-v /opt/upload:/opt/upload indicates the path mapping between the host and the nginx image. This can be customized. However, note that if you use a customized nginx configuration file, the corresponding path in the configuration file must be an internal file path of the Nginx image.

192.168.104.51:5000 / huaun/nginx: test for my local mirror mirror inside the warehouse is in native nginx mirror above made a tag, change a name, “192.168.104.51:5000 / huaun/nginx: test” can be directly replace “nginx”