How to install and configure Docker nginx

How to install and configure Docker nginx

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:
  • How to install nginx in docker and configure access via https
  • Docker installation Nginx tutorial implementation illustration
  • How to install Nginx in Docker
  • Install Nginx and configure port forwarding using Docker

<<:  Installation method of MySQL 5.7.18 decompressed version under Win7x64

>>:  A simple way to change the password in MySQL 5.7

Recommend

Detailed tutorial on installing CUDA9.0 on Ubuntu16.04

Preface: This article is based on the experience ...

Methods and techniques for designing an interesting website (picture)

Have you ever encountered a situation where we hav...

Detailed explanation of filters and directives in Vue

Table of contents vue custom directive Global Dir...

A detailed introduction to deploying RabbitMQ environment with docker

Prerequisites: Docker is already installed 1. Fin...

How to solve the problem that Seata cannot use MySQL 8 version

Possible reasons: The main reason why Seata does ...

mysql5.6.8 source code installation process

Kernel: [root@opop ~]# cat /etc/centos-release Ce...

How to switch directories efficiently in Linux

When it comes to switching directories under Linu...

jQuery to achieve sliding stairs effect

This article shares the specific code of jQuery t...

Usage of the target attribute of the html tag a

1: If you use the tag <a> to link to a page,...

Vue implements a complete process record of a single file component

Table of contents Preface Single file components ...

Implementation of Docker to build private warehouse (registry and Harbor)

As more and more Docker images are used, there ne...

Determine whether MySQL update will lock the table through examples

Two cases: 1. With index 2. Without index Prerequ...

MySQL 5.6 zip package installation tutorial detailed

Previously, we all used files with the suffix .ms...

JavaScript counts the number of times a character appears

This article example shares the specific code of ...

CSS code to control the background color of the web page

I think everyone often worries about finding pict...