加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

使用 docker 容器化个人服务器上的应用

发布时间:2020-12-16 03:51:15 所属栏目:安全 来源:网络整理
导读:Postgresql 拉取最新镜像并且启动容器。 docker run -it --name=mypostgres --rm -v /home/chencanxin/dockerdata/postgres:/var/lib/postgresql/data -p 5432:5432 postgres 其中参数说明: --rm Automatically remove the container when it exits --inter

Postgresql

  • 拉取最新镜像并且启动容器。
    docker run -it --name=mypostgres --rm -v /home/chencanxin/dockerdata/postgres:/var/lib/postgresql/data -p 5432:5432 postgres
    其中参数说明:
    --rm Automatically remove the container when it exits
    --interactive,-i Keep STDIN open even if not attached
    --tty,-t Allocate a pseudo-TTY .即分配一个终端 terminal
  • 进入容器 docker exec -it mypostgres
  • 切换为postgres用户:su postgres
  • 设置密码 alter

Redis

Mysql

Jenkins

Portainer

Nginx 转发

设置 https

http{
                #配置共享会话缓存大小,视站点访问情况设定
                 ssl_session_cache   shared:SSL:10m;
                #配置会话超时时间
                  ssl_session_timeout 10m;
                 server {
                            listen              443 ssl;
                            server_name        chencanxin.cn;

                            #设置长连接
                            keepalive_timeout   70;

                            #HSTS策略
                            add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;

                            #证书文件
                            ssl_certificate    /etc/ssl/1_chencanxin.cn_bundle.crt;
                               #私钥文件
                            ssl_certificate_key /etc/ssl/2_chencanxin.cn.key;

                            #优先采取服务器算法
                            ssl_prefer_server_ciphers on;
                            #使用DH文件
                            #ssl_dhparam /etc/ssl/certs/dhparam.pem;
                            ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
                            #定义算法
                            ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4";
                            #减少点击劫持
                            add_header X-Frame-Options DENY;
                            #禁止服务器自动解析资源类型
                            add_header X-Content-Type-Options nosniff;
                            #防XSS攻擊
                            add_header X-Xss-Protection 1;
                        }
}

重写 80 端口

server {
    listen 80;
    server_name  chencanxin.cn;
    rewrite ^(.*)$ https://${server_name}$1 permanent;

}

基于https 转发端口应用

server {
    listen              443 ssl;
    server_name        chencanxin.cn;
    #设置长连接
    keepalive_timeout   70;
    ##HSTS策略
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
    ##证书文件
    ssl_certificate    /etc/ssl/1_chencanxin.cn_bundle.crt;
    ##私钥文件
    ssl_certificate_key /etc/ssl/2_chencanxin.cn.key;
    ##优先采取服务器算法
    ssl_prefer_server_ciphers on;
    ##使用DH文件
    ##ssl_dhparam /etc/ssl/certs/dhparam.pem;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ##定义算法
    ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4";
    ##减少点击劫持
    add_header X-Frame-Options DENY;
    ##禁止服务器自动解析资源类型
    add_header X-Content-Type-Options nosniff;
    ##防XSS攻擊
    add_header X-Xss-Protection 1;
                            location /usermanage/api/ {
                                                proxy_pass http://localhost:8083;
                                                proxy_redirect default;
                                                proxy_set_header Host $host;
                                                proxy_set_header Remote_addr $remote_addr;
                        }

                        location /usermanage/ {
                                           proxy_redirect off;
                                           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_pass http://localhost:8082;
                                           proxy_read_timeout  90;
                        }


                        location / {
                                            rewrite ".*" https://segmentfault.com/blog/chencanxin;
                         }

}

nginx proxy_pass 的坑

location 后面紧跟的路径最后,加和不加“/”,是有区别的,具体见下文:

https://blog.csdn.net/zhongzh86/article/details/70173174

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读