docker安装nginx

1.pull nginx

docker pull nginx

 2.安装docker

docker run --name nginx -p 80:80 -d nginx

3.将容器中的相应文件copy到刚创建的管理目录中

mkdir /opt/docker/nginx/
docker cp nginx:/etc/nginx/nginx.conf /opt/docker/nginx/
docker cp nginx:/etc/nginx/conf.d /opt/docker/nginx/conf.d/
docker cp nginx:/usr/share/nginx/html/ /opt/docker/nginx/html/
docker cp nginx:/var/log/nginx/ /opt/docker/nginx/logs/
docker cp nginx:/etc/nginx/cert/ /opt/docker/nginx/cert/
如:
/etc/nginx/cert不存在,则需先在容器中创建改目录

4.停止并移除容器

docker stop nginx
docker rm nginx

5.重新挂载

docker run --name nginx -p 80:80 -p 443:443 -v /opt/docker/nginx/nginx.conf:/etc/nginx/nginx.conf -v /opt/docker/nginx/html/:/usr/share/nginx/html/ -v /opt/docker/nginx/logs/:/var/log/nginx/ -v /opt/docker/nginx/conf.d/:/etc/nginx/conf.d -v /opt/docker/nginx/cert/:/etc/nginx/cert --privileged=true -d nginx

6.挂载web应用

# 舟山跨境综试区后台
server {
  listen 80;
  server_name admin.zszsq.com.cn;
  client_max_body_size 50M;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";
  root /usr/share/nginx/html/kjzsq_admin/;

  location / {
    try_files $uri $uri/ @router;
    index index.html;
  }

  location @router {
    rewrite ^.*$ /index.html last;
  }

  location ^~/dev-api/ {
    proxy_pass http://172.18.0.1:1011/;
  }
}

server {
        ssl on;
        listen 443 ssl http2;
        server_name admin.zszsq.com.cn;
        ssl_certificate cert/8919886__zszsq.com.cn.pem;
        ssl_certificate_key cert/8919886__zszsq.com.cn.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;
        root /usr/share/nginx/html/kjzsq_admin/;

        location / {
                try_files $uri $uri/ @router;
        index index.html;
        }

        location @router {
                rewrite ^.*$ /index.html last;
        }

        location ^~/dev-api/ {
                proxy_pass http://172.18.0.1:1011/;
        }
        # 避免端点安全问题
    if ($request_uri ~ "/actuator"){
        return 403;
    }
}
posted @ 2021-06-10 15:11  方大帝的博客  阅读(474)  评论(0编辑  收藏  举报