Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and mount nginx in Docker

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

It is believed that many inexperienced people have no idea about how to install and mount nginx in Docker. Therefore, this article summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

1. Pull the nginx image using docker

Docker installation reference Centos7 installation configuration Docker

Docker pull nginx

Create the corresponding mount directory that needs to be mounted

Confirm the directory files that need to be mounted

You can start nginx first and check inside the container.

Docker run-p 80:80-name nginx-d nginxdocker exec-it container id / bin/bash; # enter the nginx container and browse the configuration of / etc/nginx/

You can see that in nginx.conf, the default.conf under / etc/nginx/conf.d is introduced.

The main purpose is to remember these file locations for easy mounting.

Html file path: / usr/share/nginx/html configuration file path: / etc/nginx/nginx.conf / opt/nginx/conf/conf.d log storage path: / var/log/nginx

Exit exits the container.

It is recommended to copy the file first and then start it. Docker recommends mounting the directory. If you mount a directory, docker starts to look for the configuration files mounted in the mounted host, so you must first copy the configuration files to the host directory.

Docker cp Container id:/etc/nginx / opt/nginx/confdocker cp Container id:/usr/share/nginx/html / opt/nginx/conf

Start docker

Docker run-p 8001restart always 80-- name nginx-- restart always-v / opt/nginx/html:/usr/share/nginx/html-v / opt/nginx/conf:/etc/nginx-v / opt/nginx/conf/conf.d:/etc/nginx/conf.d-v / opt/nginx/logs:/var/log/nginx-d nginx

Check the path because you are copying a directory. There will be an extra layer of nginx in the conf file copied to the host. You can manually move it to the upper conf directory, or specify the correct directory when mounting.

Browser visit: http://ip:8001, the welcome page appears indicating that the startup is successful.

Check whether the mount is successful:

Modify the index.html page under / opt/nginx/html

Remember to specify the encoding format, otherwise the Chinese will be garbled. There is no need to modify configuration files on the Internet. You only need to specify the encoding format.

Restart nginx

Docker restart nginx

Browser input: http://ip:8001

Mounted successfully.

4. Set it as a static file server

1. Modify the default.conf under / opt/nginx/conf/conf.d

Display all files autoindex on in a tree structure

Autoindex_exact_size off; defaults to on, which shows the exact size of the file, in bytes. After changing to off, the approximate size of the file is displayed, in kB or MB or GB

Autoindex_localtime on; defaults to off, and the file time displayed is GMT time. When changed to on, the file time displayed is the server time of the file

two。 Delete the index.html page under / opt/nginx/html or change the file name. Otherwise, the home page will be opened by default.

After reading the above, have you mastered how to install and mount nginx in Docker? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report