Download Nginx image in Docker docker pull nginx docker images Create a mount directory mkdir -p /data/nginx/{conf,conf.d,html,logs} Write the nginx.conf configuration file and put it in the folder # For more information on configuration, see: # * Official English Documentation: http://nginx.org/en/docs/ # * Official Russian Documentation: http://nginx.org/ru/docs/ user nginx; worker_processes auto; error_log /var/log/nginx/error.log; pid /run/nginx.pid; # Load dynamic modules. See /usr/share/nginx/README.dynamic. include /usr/share/nginx/modules/*.conf; events { worker_connections 1024; } http { 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; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80 default_server; listen [::]:80 default_server; server_name 182.254.161.54; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { proxy_pass http://pic; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } } upstream pic{ server 182.254.161.54:8088 weight=5; server 182.254.161.54:8089 weight=5; } } Start the container Copy the code as follows: docker run --name mynginx -d -p 82:80 -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /data/nginx/logs:/var/log/nginx -d docker.io/nginx View the started container docker ps Previously, two tomcats have been deployed in Docker, one is port 8088 and the other is port 8089, and simple pages have been written in the two containers. Access port 8088 Access port 8089 Now we use Nginx to access the contents of the two tomcats to achieve load balancing. For the sake of difference, the load balancing function can be better reflected. The contents of the two pages are different, but the access paths are the same. We just use Nginx reverse proxy to access them in rotation. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Installation method of MySQL 5.7.18 decompressed version under Win7x64
>>: A simple way to change the password in MySQL 5.7
Basic knowledge of responsive layout development ...
Table of contents 1. Introduction 2. Introduction...
Table of contents 1. Grammar 2. Examples 3. Other...
Table of contents Product Requirements Ideas Prob...
Table of contents Generate random numbers Generat...
Use of AES encryption Data transmission encryptio...
This article mainly introduces the sample code of...
CentOS 8 has been released for a long time. As so...
Table of contents 1. What is Bubble Sort 2. Give ...
Table of contents 1. Change the 2375 port of Dock...
I spent almost two hours trying various methods. ...
Ubuntu 15.04 opens MySQL remote port 3306. All th...
Table of contents 1. Introduction 2. Rendering 3....
1. Case Take all employees who are not the head o...
Table of contents Preface 1. Prepare new partitio...