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 start nginx and configure and modify the configuration file of nginx on docker

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article introduces the knowledge of "how to start nginx and configure and modify the configuration file of nginx on docker". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Download the nginx image docker pull nginx using docker

two。 Start nginx

Docker run-- name nginx-p 80:80-d nginx

This simply starts nginx, but we want to change the configuration file nginx.conf, enter the container, and command:

Docker exec-it nginx bash

The nginx.conf configuration file is under / etc/nginx/, but you use vim nginx.conf or vi nginx.conf

You will find that the vi or vim commands are useless. The solution: apt-get install vim after the apt-get update is completed.

At this point, you can customize the nginx.con file yourself. Restart the container after changing the configuration file. Step, stop the container first.

Docker stop nginx then restarts docker start nginx

This is not very convenient. There is a second way to mount the configuration file, which is to map the nginx.conf configuration file installed on the docker host to the startup nginx container. This requires that you first prepare the nginx.con configuration file. If you are ready, the next step is to start nginx.

Command: docker run-- name nginx-p 80:80-v / home/docker-nginx/nginx.conf:/etc/nginx/nginx.conf-v / home/docker-nginx/log:/var/log/nginx-v / home/docker-nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf-d nginx

Explain the above command:

Name gives you a name for the container you start, and you can use this name to start or stop the container later.

-p map port to bind port 80 of docker host to port 80 of container

-v is used for mounting files. The first-v means to overwrite your local nginx.conf to the nginx.conf file of the container you want to start, and the second means to mount the log file, that is, to write the log of the nginx server to your docker host / home/docker-nginx/log/.

The third-v means the same thing as the first-v.

-d indicates which mirror is started

Personally, I prefer the second way of mapping. The trouble is that I need to prepare my own nginx.conf and default.conf files. I copied them directly from the container and changed them according to my own needs.

This is the end of the introduction of "how to start nginx and configure and modify the configuration file of nginx on docker". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

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

Servers

Wechat

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

12
Report