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

Steps for docker nginx to configure load balancin

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly explains the steps of configuring load balancing in docker nginx. The explanation in this article is simple and clear, and is easy to learn and understand. Please follow the editor's train of thought to study and learn the steps of configuring load balancing in docker nginx.

1. Download nginx

Docker pull nginx

two。 Start nginx

Docker run-d-m 2g-p 8888purl 80-- name lyjng nginx

3. Configure Mappin

Create a directory: mkdir-p / root/lyjnginx/nginx/www / root/lyjnginx/nginx/logs / root/lyjnginx/nginx/conf

Where:

Www: the directory will be mapped to the virtual directory configured by the nginx container.

Logs: the directory will map to the log directory of the nginx container.

Conf: the configuration file in the directory will be mapped to the configuration file of the nginx container.

4. Copy files in a docker container

[root@ambari-01 lyjnginx] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMEScf7da4042664 nginx "/ docker-entrypoint." 20 minutes ago Up 20 minutes 0.0.0.0 80/tcp 8888-> 80/tcp lyjng [root @ ambari-01 lyjnginx] # docker cp cf7da4042664:/etc/nginx/nginx.conf / root/lyjnginx/nginx/conf/

5. Deployment command

Docker run-m 2g-- rm-d-p 8889 root/lyjnginx/nginx/www:/usr/share/nginx/html 80-- name nginx-test-web-v / root/lyjnginx/nginx/www:/usr/share/nginx/html-v / root/lyjnginx/nginx/conf/nginx.conf:/etc/nginx/nginx.conf-v / root/lyjnginx/nginx/logs:/var/log/nginx nginx

Command description:

-m: set the container to occupy memory

-- rm: automatically delete container files when the container is terminated.

-p 8889 rig 80: map port 80 of the container to port 8889 of the host.

-- name nginx-test-web: name the container nginx-test-web

-v / root/lyjnginx/nginx/www:/usr/share/nginx/html: Mount the www directory we created to the container's / usr/share/nginx/html.

-v / root/lyjnginx/nginx/conf/nginx.conf:/etc/nginx/nginx.conf: Mount the nginx.conf we created to the / etc/nginx/nginx.conf of the container.

-v / root/lyjnginx/nginx/logs:/var/log/nginx: Mount the logs we created to the / var/log/nginx of the container.

6. Configure nginx.conf and restart the docker nginx container by modifying the / root/lyjnginx/nginx/conf/nginx.conf file.

User nginx;worker_processes 1 errorists log / var/log/nginx/error.log warn;pid / var/run/nginx.pid;events {worker_connections 1024;} http {include / etc/nginx/mime.types; default_type application/octet-stream Log_format main'$remote_addr-$remote_user [$time_local] "$request"'$status $body_bytes_sent "$http_referer"'"$http_user_agent"$http_x_forwarded_for"; access_log / var/log/nginx/access.log main; sendfile on; # tcp_nopush on; keepalive_timeout 65; # gzip on # this line must be commented, otherwise / etc/nginx/conf.d/*.conf will overwrite the configuration lyj # include / etc/nginx/conf.d/*.conf; # in server {} below, which is the lyj upstream front_server_load {# ip_hash directive to add load balancer configuration to introduce the same user to the same server. Ip_hash; server 192.168.1.134fail_timeout=60s; server 192.168.3.175 fail_timeout=60s; server 8089;} # this is to add the load balancer configuration lyj server {listen 80; server_name localhost; location / {proxy_pass http://front_server_load; } docker run-m 2g-- rm-d-p 8090 root/lyjnginx/nginx/www:/usr/share/nginx/html 80-- name nginx-load-v root/lyjnginx/nginx/www:/usr/share/nginx/html-v / root/lyjnginx/conf/nginx.conf:/etc/nginx/nginx.conf-v / root/lyjnginx/logs:/var/log/nginx nginx Thank you for reading. This is the content of "steps for configuring load balancing in docker nginx". After the study of this article I believe you have a deeper understanding of the steps of configuring load balancer in docker nginx, and the specific usage needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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