docker部署solo网站

Published on in 技术分享 with 51 views

网络准备

为了安全起见,我们定义一个私网的桥接

docker network create -d bridge solonet

只允许这台主机上的容器相互连接,

mysql

由于服务器性能有限,用5.x最新版本

docker pull mysql:5.7.26


docker run --name mysql5.7 -p 3306:3306 \

--network solonet --privileged=true --restart=always \

-v /lcf/docker-data/mysql5.7/data:/var/lib/mysql \

-v /lcf/docker-data/mysql5.7/conf:/etc/mysql/conf.d \

-e TZ=Asia/Shanghai \

-e MYSQL_ROOT_PASSWORD=password -d mysql:5.7.26 \

--character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci \

--lower_case_table_names=1 --default-time_zone='+8:00'

solo


docker run -d --restart=always --name solo \

--network solonet\

--env RUNTIME_DB="MYSQL" \

--env JDBC_USERNAME="root" \

--env JDBC_PASSWORD="password" \

--env JDBC_DRIVER="com.mysql.jdbc.Driver" \

--env JDBC_URL="jdbc:mysql://mysql5.7:3306/solo?useUnicode=yes&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC" \

b3log/solo --listen_port=8080 --server_scheme=https --server_host=www.marscheng.cn --server_port=80

Nginx

新建/lcf/docker-data/nginx/conf/nginx.conf


worker_processes 1;

events {

worker_connections 1024;

}

http {

include mime.types;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

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" "$request_body"';

access_log /var/log/nginx/logs/access.log main;

sendfile on;

#开启gzip压缩

gzip on;

gzip_disable "MSIE [1-6]\.";

gzip_vary on;

gzip_proxied any;

gzip_comp_level 6;

gzip_buffers 16 8k;

gzip_min_length 256k;

gzip_types text/plain application/javascript text/css application/json application/x-javascript text/xml application/xml text/javascript;

#后端的服务器

upstream backend {

server solo:8080 max_fails=3 fail_timeout=30s;

}

#个人博客

server {

# 最新写法,ssl on 的写法已经不推荐了!

listen 443 ssl;

server_name marscheng.cn www.marscheng.cn;

# 证书相关,https新增

ssl_certificate 2396704_marscheng.cn.pem;

ssl_certificate_key 2396704_marscheng.cn.key;

ssl_session_timeout 5m;

location / {

proxy_pass http://backend$request_uri;

proxy_set_header Host $host:$server_port;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header http_x_forwarded_for $remote_addr;

client_max_body_size 10m;

}

}

server {

# http跳转到https,这样就只存在http的博客了

listen 80;

server_name marscheng.cn www.marscheng.cn;

rewrite ^(.*)$ https://$host$1 permanent;

}

}

启动ngnix容器


docker run -p 80:80 -p 443:443 -m 200m --restart always \

--name nginx --network solonet \

-v /lcf/docker-data/nginx/www:/www \

-v /lcf/docker-data/nginx/conf/:/etc/nginx/ \

-v /lcf/docker-data/nginx/logs:/var/log/nginx/logs \

-v /lcf/docker-data/nginx/wwwlogs:/wwwlogs \

nginx

最后记得开通安全组443和80的端口权限,否则会无法访问

查看docker 日志


docker logs -t -f --tail 100 solo

当然也可以写一个docker compose去一键部署,有时间再补充下


标题:docker部署solo网站
作者:MarsChan
地址:https://www.marscheng.cn/articles/2019/06/25/1561464062101.html

Responses