First, create a tomcat folder. To facilitate the configuration of docker, I will create it directly in the root directory. Step 1: Create a folder: Publish folder mkdir -p /docker/tomcat/webapp8081 mkdir -p /docker/tomcat/webapp8082 mkdir -p /docker/tomcat/webapp8083 Step 2: Create a Tomcat container (the port can be changed according to your actual situation) docker run -d --name tomcat8081 -p 8081:8080 -v /docker/tomcat/webapp8081:/usr/local/tomcat/webapps/ tomcat docker run -d --name tomcat8082 -p 8082:8080 -v /docker/tomcat/webapp8082:/usr/local/tomcat/webapps/ tomcat docker run -d --name tomcat8083 -p 8083:8080 -v /docker/tomcat/webapp8083:/usr/local/tomcat/webapps/ tomcat After the creation is complete, use the docker ps command to check whether the creation is successful and use Step 3: Check the IP address of Tomcat. Use the following commands to query the IP address of Tomcat. Here we only use the first example. Step 4: For the convenience of testing, I will not upload the war package here, but directly create a hello/index.html file in it Note: If Nginx is a Docker container, you must use the Tomact container IP, otherwise you will not be able to connect First download the official version of nginx from the official website Official website: http://nginx.org/en/ Click download in the right navigation bar, enter the download interface and select the corresponding version to download. I will use nginx-1.6.2.tar here. After the download is complete, put the file in a custom folder, I put it in /usr/local/tools/nginx-1.6.2 Unzip nginx using this command: After the decompression is complete, I return to the root directory and create a host folder in the root directory to create files so that nginx can mount (you can also customize it) Create a host folder here mkdir -p /docker/nginx/ vim /docker/nginx/nginx.conf mkdir -p /docker/nginx/html Copy the index.html 50x.html in the html folder of the unzipped negix to the /docker/nginx/html folder Here is a negix conf file. The format may change due to annotations. Remember to delete the annotations. Nginx.conf: user root; worker_processes 2; #Set your number of threads here #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; #Maximum number of connections} http { include mime.types; default_type application/octet-stream; upstream mytomcat{ server 172.17.0.3:8080 weight=10; # In addition, the name of mytomcat should be consistent with the name below. It should be consistent with your tomcat IP. server 172.17.0.4:8080 weight=50; server 172.17.0.5:8080 weight=10; } #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 logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name mytomcat; #charset koi8-r; #access_log logs/host.access.log main; location / { #root html; # index index.html index.htm; proxy_connect_timeout 50; proxy_read_timeout 10; proxy_send_timeout 20; proxy_pass http://mytomcat; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { #root html; # fastcgi_pass 127.0.0.1:9000; # 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; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { #root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; #ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { #root html; # index index.html index.htm; # } #} } Start using docker Create and run the container 81: This is the port for external network access. You can modify it according to your actual situation. /docker/nginx/nginx.conf local host file /etc/nginx/nginx.conf The directory where the zip file is extracted (you can also leave it unchanged) /docker/nginx/html local host file /usr/share/nginx/html Unzip directory docker run -d --name nginx81 -p 81:80 -v /docker/nginx/nginx.conf:/etc/nginx/nginx.conf -v /docker/nginx/html:/usr/share/nginx/html nginx test http://39.106.147.162:8085/hello/index.html I have configured port 8085 here Direct access Summarize The above is the tutorial on how to use Docker to build a tomcat cluster using nginx. I hope it will be helpful to you! You may also be interested in:
|
<<: Two query methods when the MySQL query field type is json
>>: Node and Python two-way communication implementation code
There are some issues that are not limited to Vue...
Based on theories such as Saussure's philosop...
Table of contents Preface Using websocket Constru...
When deleting a table or a piece of data in MySQL...
1. Overview of viewport Mobile browsers usually r...
<!--[if lte IE 6]> <![endif]--> Visibl...
This article uses examples to describe MySQL tran...
This article uses examples to describe the basic ...
<br />In the first section of this series, w...
So after registering a domain name and purchasing...
Table of contents Multi-application deployment 1-...
effect: The GROUP_CONCAT function can concatenate...
Some fault code tables use the following design p...
1. Simulate database data 1-1 Create database and...
GreaseMokey (Chinese people call it Grease Monkey...