Docker 部署 nginx + tomcat

簡介

在生產環境中,不少企業會常用nginx + tomcat 架構,nginx做爲負載均衡器,反向代理,tomcat做爲節點服務器。在docker容器中也能夠使用這種架構。
對這種架構感興趣的能夠參考博客:https://blog.51cto.com/13760351/2161850html

操做環境

Docker 部署 nginx + tomcat

備註:實驗中已關閉防火牆,打好企業使用的war包nginx

部署過程:

1、安裝nginx鏡像

可參考博客 https://blog.51cto.com/13760351/2469063docker

2、部署war包項目

部署及排坑過程可參考博客 https://blog.51cto.com/13760351/2469305vim

3、修改nginx配置文件

vim /etc/nginx/nginx.conftomcat

user  nginx;
worker_processes  1;
error_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" "$upstream_addr"';

    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    keepalive_timeout  65;
    #gzip  on;
    upstream tomcat {
        server 47.99.150.153:8088 weight=1;  #添加權重
        server 47.99.150.155:8088 weight=1;
    }

    server {
        listen 80;
        server_name localhost;

                location / {
            root  /usr/share/nginx/html;
            index  index.html index.htm;
            }

        location /admin {
            proxy_pass http://tomcat;  #添加
            proxy_redirect off;
            index index.html index.htm;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Real-Port $remote_port;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        }
    }

    include /etc/nginx/conf.d/*.conf;
}

4、網頁驗證

Docker 部署 nginx + tomcat

相關文章
相關標籤/搜索