docker-compose 部署 Nginx、Postgres、redis、java应用

文件夹结构

C:\Users\Administrator\Desktop\lsheet>tree /f
│ 
│  docker-compose.yml   #部署文件
│
├─java-server
│      application-dev.yml           #项目配置
│      application.yml                  #项目配置 
│      web-lockysheet-server.jar   #项目
│
├─nginx
│  │  nginx.conf  #nginx 配置
│  │
│  ├─html         #nginx 静态文件夹
│  └─logs          #nginx 日志文件夹
├─postgres
│  │  init.sql      #postgre 初始化文件
│  │
│  └─data          #postgres 数据文件夹
└─redis
    │  redis.conf   #redis 配置文件
    │ 
    ├─data          #redis 数据文件夹
    └─logs           #redis 日志文件夹

准备工作

安装 docker

安装 docker-compose

安装 curl

yum install curl

 

1、进入文件夹

 2、设置 redis/logs 目录权限

chmod a+rwx ./redis/logs/

 3、开始构建生成镜像

docker-compose build

 4、后台启动容器

docker-compose up -d 

 5、查看镜像

docker ps

 6、验证

1)redis 验证

 docker exec -it  容器 ID  redis-cli -a '123456'

 2)postgres 验证

#进入容器
docker exec -ti postgres /bin/bash
#登陆 postgres
psql -U postgres
#列出全部数据库
\l
#切换数据库
\c luckysheetdb
#列出全部表名
\dt
#查看表数据
select * from luckysheet;

 3)验证 java 应用(使用测试 url)

curl http://172.19.0.4:9004/luckysheet/test/constant?param=123

 4)验证 nginx 访问 java 应用

curl http://172.19.0.101/luckysheet/test/constant?param=123

 5)本示例是安装在云服务器上,通过浏览器测试

http://xx.100.104.9/luckysheet/test/constant?param=123

 7、配置文件

1)nginx 配置

#运行用户
#user  nobody;

#开启进程数 <=CPU 数
worker_processes
1;

#错误日志保存位置
error_log /var/log/nginx/error.log;

#进程号保存文件
pid /var/log/nginx/nginx.pid;

#等待事件
events {
#Linux 下打开提高性能
#use epoll;
#每个进程最大连接数(最大连接 =连接数 x 进程数)
worker_connections
1024;
}

http {
#文件扩展名与文件类型映射表
include mime.types;

#默认文件类型
default_type  application</span>/octet-<span style="color: rgba(0, 0, 0, 1)">stream;

#日志文件输出格式 这个位置相于全局设置
log_format  main  </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">$remote_addr - $remote_user [$time_local] "$request" </span><span style="color: rgba(128, 0, 0, 1)">'</span>
                  <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">$status $body_bytes_sent "$http_referer" </span><span style="color: rgba(128, 0, 0, 1)">'</span>
                  <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">"$http_user_agent" "$http_x_forwarded_for"</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">;

#请求日志保存位置
access_log  </span>/<span style="color: rgba(0, 0, 255, 1)">var</span>/log/nginx/<span style="color: rgba(0, 0, 0, 1)">access.log  main;

#打开发送文件
sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">;
keepalive_timeout  </span><span style="color: rgba(128, 0, 128, 1)">65</span><span style="color: rgba(0, 0, 0, 1)">;

#打开gzip压缩
#gzip  on;
gzip  on;
gzip_min_length 1k;
gzip_buffers </span><span style="color: rgba(128, 0, 128, 1)">16</span><span style="color: rgba(0, 0, 0, 1)"> 64k;
gzip_http_version </span><span style="color: rgba(128, 0, 128, 1)">1.0</span><span style="color: rgba(0, 0, 0, 1)">;
gzip_comp_level </span><span style="color: rgba(128, 0, 128, 1)">7</span><span style="color: rgba(0, 0, 0, 1)">;
#DO NOT zip pics
gzip_types text</span>/plain application/x-javascript text/javascript application/x-httpd-php text/css text/xml text/jsp application/eot application/ttf application/otf application/svg application/<span style="color: rgba(0, 0, 0, 1)">woff;
gzip_vary on;
gzip_disable </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">MSIE [1-6].</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">;

#websocket
map $http_upgrade $connection_upgrade {
    </span><span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)"> upgrade;
    </span><span style="color: rgba(128, 0, 0, 1)">''</span><span style="color: rgba(0, 0, 0, 1)">      close;
}

#设定负载均衡的服务器列表
upstream luckysheetserver {
    server </span><span style="color: rgba(128, 0, 128, 1)">172.19</span>.<span style="color: rgba(128, 0, 128, 1)">0.4</span>:<span style="color: rgba(128, 0, 128, 1)">9004</span> weight=<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">;  
}

#第一个虚拟主机
server {
    #监听IP端口
    listen       </span><span style="color: rgba(128, 0, 128, 1)">80</span><span style="color: rgba(0, 0, 0, 1)">;
    
    #主机名
    server_name  localhost;
    
    #设置字符集
    #charset koi8</span>-<span style="color: rgba(0, 0, 0, 1)">r;

    #本虚拟server的访问日志 相当于局部变量 
    #access_log  logs</span>/<span style="color: rgba(0, 0, 0, 1)">host.access.log  main;
    
    proxy_set_header X</span>-Forwarded-<span style="color: rgba(0, 0, 0, 1)">Host $host;
    proxy_set_header X</span>-Forwarded-<span style="color: rgba(0, 0, 0, 1)">Server $host;
    proxy_set_header X</span>-Forwarded-<span style="color: rgba(0, 0, 0, 1)">For $proxy_add_x_forwarded_for;

    location </span>/luckysheet/websocket/<span style="color: rgba(0, 0, 0, 1)">luckysheet {
        proxy_pass http:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">luckysheetserver/luckysheet/websocket/luckysheet;</span>
proxy_set_header Host $host; proxy_set_header X-real-ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 1800s; proxy_read_timeout 600s; proxy_send_timeout 600s; #websocket proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location /luckysheet/ { proxy_pass http://luckysheetserver; proxy_connect_timeout 1800; proxy_read_timeout 600; }
    location </span>/<span style="color: rgba(0, 0, 0, 1)"> {
        root   </span>/usr/share/nginx/html/<span style="color: rgba(0, 0, 0, 1)">;
        index  index.html index.htm;            
        
        proxy_connect_timeout </span><span style="color: rgba(128, 0, 128, 1)">1800</span><span style="color: rgba(0, 0, 0, 1)">;
        proxy_read_timeout </span><span style="color: rgba(128, 0, 128, 1)">600</span><span style="color: rgba(0, 0, 0, 1)">;
        #websocket
        proxy_http_version </span><span style="color: rgba(128, 0, 128, 1)">1.1</span><span style="color: rgba(0, 0, 0, 1)">;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">upgrade</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">;
    }

    #动静分离
    location </span>~ .*\.(html|js|css|jpg|txt)?<span style="color: rgba(0, 0, 0, 1)">$ {
       root  </span>/usr/share/nginx/html/<span style="color: rgba(0, 0, 0, 1)">;
       #expires 3d;
    }
    
    error_page   </span><span style="color: rgba(128, 0, 128, 1)">500</span> <span style="color: rgba(128, 0, 128, 1)">502</span> <span style="color: rgba(128, 0, 128, 1)">503</span> <span style="color: rgba(128, 0, 128, 1)">504</span>  /<span style="color: rgba(0, 0, 0, 1)">50x.html;
    location </span>= /<span style="color: rgba(0, 0, 0, 1)">50x.html {
        root   </span>/usr/share/nginx/html/<span style="color: rgba(0, 0, 0, 1)">;
    }

}

}

2)redis 配置

bind *
protected-mode no
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
supervised no
pidfile /usr/local/redis/redis.pid
loglevel notice
logfile /usr/local/redis/logs.log
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /usr/local/redis/data/
slave-serve-stale-data yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
maxmemory 500mb
maxmemory-policy noeviction
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
requirepass 123456

3)postgres 初始化脚本

CREATE DATABASE luckysheetdb;
\c luckysheetdb;

DROP SEQUENCE IF EXISTS "public"."luckysheet_id_seq";
CREATE SEQUENCE
"public"."luckysheet_id_seq"
INCREMENT
1
MINVALUE
1
MAXVALUE
9999999999999
START
1
CACHE
10;

DROP TABLE IF EXISTS "public"."luckysheet";
CREATE TABLE
"luckysheet" (
"id" int8 NOT NULL,
"block_id" varchar(200) COLLATE "pg_catalog"."default" NOT NULL,
"index" varchar(200) COLLATE "pg_catalog"."default" NOT NULL,
"list_id" varchar(200) COLLATE "pg_catalog"."default" NOT NULL,
"status" int2 NOT NULL,
"json_data" jsonb,
"order" int2,
"is_delete" int2
);
CREATE INDEX
"block_id" ON "public"."luckysheet" USING btree (
"block_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
"list_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX
"index" ON "public"."luckysheet" USING btree (
"index" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
"list_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX
"is_delete" ON "public"."luckysheet" USING btree (
"is_delete" "pg_catalog"."int2_ops" ASC NULLS LAST
);
CREATE INDEX
"list_id" ON "public"."luckysheet" USING btree (
"list_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST
);
CREATE INDEX
"order" ON "public"."luckysheet" USING btree (
"list_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
"order" "pg_catalog"."int2_ops" ASC NULLS LAST
);
CREATE INDEX
"status" ON "public"."luckysheet" USING btree (
"list_id" COLLATE "pg_catalog"."default" "pg_catalog"."text_ops" ASC NULLS LAST,
"status" "pg_catalog"."int2_ops" ASC NULLS LAST
);
ALTER TABLE
"public"."luckysheet" ADD CONSTRAINT "luckysheet_pkey" PRIMARY KEY ("id");

INSERT INTO "public"."luckysheet" VALUES (nextval('luckysheet_id_seq'), 'fblock', '1', '1079500#-8803#7c45f52b7d01486d88bc53cb17dcd2c3', 1, '{"row":84,"name":"Sheet1","chart":[],"color":"","index":"1","order":0,"column":60,"config":{},"status":0,"celldata":[],"ch_width":4748,"rowsplit":[],"rh_height":1790,"scrollTop":0,"scrollLeft":0,"visibledatarow":[],"visibledatacolumn":[],"jfgird_select_save":[],"jfgrid_selection_range":{}}', 0, 0);
INSERT INTO
"public"."luckysheet" VALUES (nextval('luckysheet_id_seq'), 'fblock', '2', '1079500#-8803#7c45f52b7d01486d88bc53cb17dcd2c3', 0, '{"row":84,"name":"Sheet2","chart":[],"color":"","index":"2","order":1,"column":60,"config":{},"status":0,"celldata":[],"ch_width":4748,"rowsplit":[],"rh_height":1790,"scrollTop":0,"scrollLeft":0,"visibledatarow":[],"visibledatacolumn":[],"jfgird_select_save":[],"jfgrid_selection_range":{}}', 1, 0);
INSERT INTO
"public"."luckysheet" VALUES (nextval('luckysheet_id_seq'), 'fblock', '3', '1079500#-8803#7c45f52b7d01486d88bc53cb17dcd2c3', 0, '{"row":84,"name":"Sheet3","chart":[],"color":"","index":"3","order":2,"column":60,"config":{},"status":0,"celldata":[],"ch_width":4748,"rowsplit":[],"rh_height":1790,"scrollTop":0,"scrollLeft":0,"visibledatarow":[],"visibledatacolumn":[],"jfgird_select_save":[],"jfgrid_selection_range":{}}', 2, 0);

4)docker-compose 文件

version: "2"
services:

nginx:
image: nginx:latest
#restart: always
container_name: nginx
environment:
- TZ=Asia/Shanghai
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/logs:/var/log/nginx/
- ./nginx/html:/usr/share/nginx/html/
- /etc/localtime:/etc/localtime
networks:
extnetwork:
ipv4_address:
172.19.0.101

redis:
image: redis:latest
container_name: redis
#restart: always
environment:
- TZ=Asia/Shanghai
command: redis
-server /usr/local/etc/redis/redis.conf --requirepass 123456
ports:
- "6379:6379"
volumes:
- ./redis/data:/usr/local/redis/data/
- ./redis/logs:/usr/local/redis/
- ./redis/redis.conf:/usr/local/etc/redis/redis.conf
- /etc/localtime:/etc/localtime
networks:
extnetwork:
ipv4_address:
172.19.0.2

postgres:
image: postgres:12
#restart: always
privileged:
true
container_name: postgres
ports:
- 5432:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD:
123456
PGDATA:
/var/lib/postgresql/data/pgdata
volumes:
- ./postgres/data:/var/lib/postgresql/data/pgdata
- ./postgres/init.sql:/docker-entrypoint-initdb.d/init.sql
- /etc/localtime:/etc/localtime
networks:
extnetwork:
ipv4_address:
172.19.0.3

web-server:
image: java:
8
#restart: always
privileged:
true
ports:
- 9004:9004
volumes:
- ./java-server/web-lockysheet-server.jar:/usr/local/luckysheet-server/app.jar
- ./java-server/application.yml:/usr/local/luckysheet-server/application.yml
- ./java-server/application-dev.yml:/usr/local/luckysheet-server/application-dev.yml
- /etc/localtime:/etc/localtime
command: [
'java',
'-Xmx200m',
'-jar',
'/usr/local/luckysheet-server/app.jar',
'--spring.config.location=/usr/local/luckysheet-server/application.yml,/usr/local/luckysheet-server/application-dev.yml'
]
networks:
extnetwork:
ipv4_address:
172.19.0.4

networks:
extnetwork:
ipam:
config:
- subnet: 172.19.0.0/16
gateway:
172.19.0.1

 

注:docker-compose 使用 host 部署(非固定 IP)

1)docker-compose.yml

version: "2"
services:

redis:
image: redis:latest
container_name: luckysheet-redis
#restart: always
environment:
- TZ=Asia/Shanghai
command: redis
-server /usr/local/etc/redis/redis.conf --requirepass 123456
ports:
- "6379:6379"
volumes:
- ./redis/data:/usr/local/redis/data/
- ./redis/logs:/usr/local/redis/
- ./redis/redis.conf:/usr/local/etc/redis/redis.conf
- /etc/localtime:/etc/localtime
networks:
- luckysheet-net

postgres:
image: postgres:12
#restart: always
privileged:
true
container_name: luckysheet
-postgres
ports:
- 5432:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD:
123456
PGDATA:
/var/lib/postgresql/data/pgdata
volumes:
- ./postgres/data:/var/lib/postgresql/data/pgdata
- ./postgres/init.sql:/docker-entrypoint-initdb.d/init.sql
- /etc/localtime:/etc/localtime
networks:
- luckysheet-net

web-server:
image: java:
8
#restart: always
privileged:
true
container_name: luckysheet
-server
ports:
- 9004:9004
volumes:
- ./java-server/web-luckysheet-server.jar:/usr/local/luckysheet-server/app.jar
- ./java-server/application.yml:/usr/local/luckysheet-server/application.yml
- ./java-server/application-dev.yml:/usr/local/luckysheet-server/application-dev.yml
- /etc/localtime:/etc/localtime
command: [
'java',
'-Xmx200m',
'-jar',
'/usr/local/luckysheet-server/app.jar',
'--spring.config.location=/usr/local/luckysheet-server/application.yml,/usr/local/luckysheet-server/application-dev.yml'
]
networks:
- luckysheet-net
links:
- redis
- postgres

nginx:
image: nginx:latest
#restart: always
container_name: luckysheet-nginx
environment:
- TZ=Asia/Shanghai
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/logs:/var/log/nginx/
- ./nginx/html:/usr/share/nginx/html/
- /etc/localtime:/etc/localtime
networks:
- luckysheet-net
links:
- web-server

networks:
luckysheet-net:
external:
false

2)nginx.conf

#运行用户
#user  nobody;

#开启进程数 <=CPU 数
worker_processes
1;

#错误日志保存位置
error_log /var/log/nginx/error.log;

#进程号保存文件
pid /var/log/nginx/nginx.pid;

#等待事件
events {
#Linux 下打开提高性能
#use epoll;
#每个进程最大连接数(最大连接 =连接数 x 进程数)
worker_connections
1024;
}

http {
#文件扩展名与文件类型映射表
include mime.types;

#默认文件类型
default_type  application</span>/octet-<span style="color: rgba(0, 0, 0, 1)">stream;

#日志文件输出格式 这个位置相于全局设置
log_format  main  </span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">$remote_addr - $remote_user [$time_local] "$request" </span><span style="color: rgba(128, 0, 0, 1)">'</span>
                  <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">$status $body_bytes_sent "$http_referer" </span><span style="color: rgba(128, 0, 0, 1)">'</span>
                  <span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(128, 0, 0, 1)">"$http_user_agent" "$http_x_forwarded_for"</span><span style="color: rgba(128, 0, 0, 1)">'</span><span style="color: rgba(0, 0, 0, 1)">;

#请求日志保存位置
access_log  </span>/<span style="color: rgba(0, 0, 255, 1)">var</span>/log/nginx/<span style="color: rgba(0, 0, 0, 1)">access.log  main;

#打开发送文件
sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  </span><span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">;
keepalive_timeout  </span><span style="color: rgba(128, 0, 128, 1)">65</span><span style="color: rgba(0, 0, 0, 1)">;

#打开gzip压缩
#gzip  on;
gzip  on;
gzip_min_length 1k;
gzip_buffers </span><span style="color: rgba(128, 0, 128, 1)">16</span><span style="color: rgba(0, 0, 0, 1)"> 64k;
gzip_http_version </span><span style="color: rgba(128, 0, 128, 1)">1.0</span><span style="color: rgba(0, 0, 0, 1)">;
gzip_comp_level </span><span style="color: rgba(128, 0, 128, 1)">7</span><span style="color: rgba(0, 0, 0, 1)">;
#DO NOT zip pics
gzip_types text</span>/plain application/x-javascript text/javascript application/x-httpd-php text/css text/xml text/jsp application/eot application/ttf application/otf application/svg application/<span style="color: rgba(0, 0, 0, 1)">woff;
gzip_vary on;
gzip_disable </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">MSIE [1-6].</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">;

#websocket
map $http_upgrade $connection_upgrade {
    </span><span style="color: rgba(0, 0, 255, 1)">default</span><span style="color: rgba(0, 0, 0, 1)"> upgrade;
    </span><span style="color: rgba(128, 0, 0, 1)">''</span><span style="color: rgba(0, 0, 0, 1)">      close;
}

#设定负载均衡的服务器列表
upstream luckysheetserver {
    server web</span>-server:<span style="color: rgba(128, 0, 128, 1)">9004</span> weight=<span style="color: rgba(128, 0, 128, 1)">1</span><span style="color: rgba(0, 0, 0, 1)">;  
}

#第一个虚拟主机
server {
    #监听IP端口
    listen       </span><span style="color: rgba(128, 0, 128, 1)">80</span><span style="color: rgba(0, 0, 0, 1)">;
    
    #主机名
    server_name  localhost;
    
    #设置字符集
    #charset koi8</span>-<span style="color: rgba(0, 0, 0, 1)">r;

    #本虚拟server的访问日志 相当于局部变量 
    #access_log  logs</span>/<span style="color: rgba(0, 0, 0, 1)">host.access.log  main;
    
    proxy_set_header X</span>-Forwarded-<span style="color: rgba(0, 0, 0, 1)">Host $host;
    proxy_set_header X</span>-Forwarded-<span style="color: rgba(0, 0, 0, 1)">Server $host;
    proxy_set_header X</span>-Forwarded-<span style="color: rgba(0, 0, 0, 1)">For $proxy_add_x_forwarded_for;

    location </span>/luckysheet/websocket/<span style="color: rgba(0, 0, 0, 1)">luckysheet {
        proxy_pass http:</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">luckysheetserver/luckysheet/websocket/luckysheet;</span>
proxy_set_header Host $host; proxy_set_header X-real-ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_connect_timeout 1800s; proxy_read_timeout 600s; proxy_send_timeout 600s; #websocket proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } location /luckysheet/ { proxy_pass http://luckysheetserver; proxy_connect_timeout 1800; proxy_read_timeout 600; }
    location </span>/<span style="color: rgba(0, 0, 0, 1)"> {
        root   </span>/usr/share/nginx/html/<span style="color: rgba(0, 0, 0, 1)">;
        index  index.html index.htm;            
        
        proxy_connect_timeout </span><span style="color: rgba(128, 0, 128, 1)">1800</span><span style="color: rgba(0, 0, 0, 1)">;
        proxy_read_timeout </span><span style="color: rgba(128, 0, 128, 1)">600</span><span style="color: rgba(0, 0, 0, 1)">;
        #websocket
        proxy_http_version </span><span style="color: rgba(128, 0, 128, 1)">1.1</span><span style="color: rgba(0, 0, 0, 1)">;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">upgrade</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">;
    }

    #动静分离
    location </span>~ .*\.(html|js|css|jpg|txt)?<span style="color: rgba(0, 0, 0, 1)">$ {
       root  </span>/usr/share/nginx/html/<span style="color: rgba(0, 0, 0, 1)">;
       #expires 3d;
    }
    
    error_page   </span><span style="color: rgba(128, 0, 128, 1)">500</span> <span style="color: rgba(128, 0, 128, 1)">502</span> <span style="color: rgba(128, 0, 128, 1)">503</span> <span style="color: rgba(128, 0, 128, 1)">504</span>  /<span style="color: rgba(0, 0, 0, 1)">50x.html;
    location </span>= /<span style="color: rgba(0, 0, 0, 1)">50x.html {
        root   </span>/usr/share/nginx/html/<span style="color: rgba(0, 0, 0, 1)">;
    }

}

}

3)application-dev.yml

 

logging:
  config: classpath:logback-spring.xml

日志是否打印 sql

showSql: true

spring:
redis:
host: redis
port: 6379
password:
123456
timeout: 10000ms
lettuce:
pool:
max
-active: 8
max
-wait: -1ms
max
-idle: 8
min
-idle: 0
database:
0

db:
postgre:
druid:
url: jdbc:postgresql://postgres:5432/luckysheetdb?useSSL=false
driverClassName: org.postgresql.Driver
username: postgres
password:
123456
# 初始化大小,最小,最大
initial
-size: 8
min
-idle: 1
max
-active: 20
# 配置获取连接等待超时的时间
max
-wait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
time
-between-eviction-runsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
min
-evictable-idle-timeMillis: 300000
validation
-query: select 1
test
-while-idle: true
test
-on-borrow: false
test
-on-return: false
# 打开 PSCache,并且指定每个连接上 PSCache 的大小
pool
-prepared-statements: true
max
-open-prepared-statements: 20
# 配置监控统计拦截的 filters,去掉后监控界面 sql 无法统计,
'wall'用于防火墙
max
-pool-prepared-statement-per-connection-size: 20
filters: stat,wall
# 通过 connectProperties 属性来打开 mergeSql 功能;慢 SQL 记录
connection
-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
use
-global-data-source-stat: true

 

注:

进入容器
docker exec -ti 容器 ID /bin/bash
进入容器内 redis
docker exec -it 容器 ID  redis-cli -a '123456'
登陆 docker 查看日志
docker logs --tail 300 -f 容器 ID
设置文件夹权限
chmod a+rwx 目标