Nginx Web Hosting
Docker we use to install and run Nginx, nginx 80 port mapping to port 80 on the server. Can be modified. docker-compose.yml configured as follows:
root@faramita:/usr/local/docker/nginx# cat docker-compose.yml
version: '3.1'
services:
nginx:
restart: always
image: nginx
container_name: nginx
ports:
- 80:80
volumes:
- ./conf/nginx.conf:/etc/nginx/nginx.conf
- ./wwwroot:/usr/share/nginx/wwwroot
Start Tomcat container
version: '3'
services:
tomcat1:
image: tomcat
container_name: tomcat1
ports:
- 8080:8080
tomcat2:
image: tomcat
container_name: tomcat2
ports:
- 9090:8080
Nginx reverse proxy and load balancing
Configuration nginx.conf
Here are 80 through port access 139.224.117.172Nginx mapped to the 80-port server listens on port 80, access to the proxy server myapp1, myapp1 two tomcat (the equivalent of two servers), 139.224.117.172: 80 random access both tomcat, load balancing
root@faramita:/usr/local/docker/nginx/conf# cat nginx.conf
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream myapp1 {
server 139.224.117.172:8080 weight=10;
server 139.224.117.172:9090 weight=10;
}
server {
listen 80;
server_name 139.224.117.172;
location / {
proxy_pass http://myapp1;
index index.jsp index.html index.htm;
}
}
}
cdn server
docker-compose
root@faramita:/usr/local/docker/nginx# cat docker-compose.yml
version: '3.1'
services:
nginx:
restart: always
image: nginx
container_name: nginx
ports:
- 80:80
volumes:
- ./conf/nginx.conf:/etc/nginx/nginx.conf
- ./wwwroot:/usr/share/nginx/wwwroot
Cdn placement resource to be stored
/usr/local/docker/nginx/wwwroot/cdn/adminlte/v2.4.3
nginx.conf
root@faramita:/usr/local/docker/nginx/conf# cat nginx.conf
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name 139.224.117.172;
location / {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
root /usr/share/nginx/wwwroot/cdn;
index index.jsp index.html index.htm;
}
}
}