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 deploy Nginx on Docker

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article focuses on "how to deploy Nginx on Docker". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to deploy Nginx on Docker.

1. Download the Nginx image docker pull nginx2 from docker. Create a mount directory

After that, put the file in here and map the directory corresponding to Nginx in docker, so you don't have to change the file into the container.

Mkdir-p / data/nginx/ {conf,conf.d,html,logs} 3. In order to ensure the correctness of the file, it is recommended that you first enter the container and copy the corresponding file.

If it is inconvenient, you can open two windows, one goes into the container and copies it from the left to the right. This is to ensure that the file is correct.

# launch container docker run-itd nginx/ bin/bash# to enter container docker attach xxxxxxxxxx description file mount path nginx path configuration file nginx.conf/data/nginx/conf/nginx.conf/etc/nginx/nginx.conf configuration file conf.d folder / data/nginx/conf.d/etc/nginx/conf.d home page folder html path html folder / data/nginx/html/usr/share/nginx/html log file log file Clip / data/nginx/logs/var/log/nginx

This is the corresponding mount directory. Copy the nginx.conf file and the default.conf in conf.d to the corresponding folder, and then modify it.

4. Then just modify the default.conf file.

The most I can do here is change the port number, access path and so on.

Server {# port number listen 80; # defines using localhost to access server_name localhost; # charset koi8-r; # access_log / var/log/nginx/host.access.log main; location / {# root directory location root / usr/share/nginx/html; # index file location index 1.html } # error_page 404 / 404.html; # redirect server error pages to the static page / 50x.html # error_page 500502503504 / 50x.html; location = / 50x.html {root / usr/share/nginx/html } # proxy the PHP scripts to Apache listening on 127.0.0.1 php$ 80 # # location ~. Php$ {# proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.1 # location ~. Php$ {# root html; # fastcgi_pass 127.0.1 # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME / scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # # location ~ /\ .ht {# deny all; #}}

The 1.html for the test here wrote it himself.

Mynginx Welcome to nginx! 5. Then you can start the container docker run-- name myNginx-d-p 8089Jap80-v / data/nginx/html:/usr/share/nginx/html-v / data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf-v / data/nginx/conf.d:/etc/nginx/conf.d-v / data/nginx/logs:/var/log/nginx nginx

The mount path must be right, and don't write it wrong.

The port 80 is mapped to port 8089 of the host, so the access is port 8089. There is no need to change the default port of nginx.

Next, you can see if the container starts normally.

Docker ps

If you don't see the container, it means there's something wrong with the startup, to see if the configuration file is written incorrectly, or if the mount path is incorrect, and so on.

After launching, you can directly browse localhost:8089 to see the 1.index page you just wrote.

6. Do not stop nginx updating configuration files

It's nice to open two windows when we need to update the configuration file after we modify the configuration file.

# enter the container docker exec-it xxxxxxxxxxx / bin/bash # to test whether there is a problem with the configuration file nginx-t # if it shows successful, you can update the nginx-s reload. Now that you have a better understanding of "how to deploy Nginx on Docker", you might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

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

Development

Wechat

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

12
Report