docker pull nginx

$ docker pull nginx
$ docker run --name nginx-test -p 8081:80 -d nginx

docker config

$ mkdir -p ~/nginx/www ~/nginx/logs ~/nginx/conf
$ docker cp  d624b3debbc9(namenginx-test容器id 运行删除括号内容):/etc/nginx/nginx.conf ~/nginx/conf

  • www: 目录将映射为 nginx 容器配置的虚拟目录。
  • logs: 目录将映射为 nginx 容器的日志目录。
  • conf: 目录里的配置文件将映射为 nginx 容器的配置文件。

docker nginx 挂载相应的文件

$ docker run -d -p 8082:80 \
--name nginx-test-web \
-v ~/nginx/www:/usr/share/nginx/html \
-v ~/nginx/conf/nginx.conf:/etc/nginx/nginx.conf \
-v ~/nginx/logs:/var/log/nginx \
nginx

  • -p 8082:80: 将容器的 80 端口映射到主机的 8082 端口。

  • --name nginx-test-web:将容器命名为 nginx-test-web。

  • ~/nginx/www:/usr/share/nginx/html:将我们自己创建的 www 目录挂载到容器的 /usr/share/nginx/html。

  • -v ~/nginx/conf/nginx.conf:/etc/nginx/nginx.conf:将我们自己创建的 nginx.conf 挂载到容器的 /etc/nginx/nginx.conf。

  • -v ~/nginx/logs:/var/log/nginx:将我们自己创建的 logs 挂载到容器的 /var/log/nginx。

部署dist

将实现准备好的静态网页放置在~/nginx/www

$ docker kill -s HUP container-name
$ docker restart container-name

HTML5 History 模式 设置重定向

nginx

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

nginx.conf 经测试文件可以使用


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"'; access_log /var/log/nginx/access.log main; sendfile on;
#tcp_nopush on; keepalive_timeout 65; #gzip on; include /etc/nginx/conf.d/*.conf; server {
listen 80 default_server;
listen [::]:80 default_server; root /usr/share/nginx/html; index index.html; # server_name you.server.com; location / {
try_files $uri $uri/ @rewrites;
} location @rewrites {
rewrite ^(.+)$ /index.html last;
} location ~* \.(?:ico|css|js|gif|jpe?g|png)$ {
# Some basic cache-control for static files to be sent to the browser
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
}
}

学习docker 部署nginx记录的更多相关文章

  1. Docker部署Nginx并修改配置文件

    Docker部署Nginx并修改配置文件 一.拉取nginx镜像 docker pull nginx 二.在宿主机中创建挂载目录 mkdir -p /data/nginx/{conf,conf.d,h ...

  2. Docker部署Nginx应用(2)

    Docker部署Nginx应用(2) 1.拉取Nginx镜像 [root@localhost ~]# docker pull nginx Using default tag: latest lates ...

  3. docker(部署常见应用):docker部署nginx

    上回说到centos安装docker. 这次用实战,docker部署运行常见的应用. docker常用命令 参看:docker命令大全.这里不做赘述. docker部署nginx 1.docker h ...

  4. 使用docker部署nginx+tomcat架构(3):使用docker-compose简化部署操作

    经历了之前的两篇,我们已经大体上了解了docker部署容器的过程. 使用docker部署nginx+tomcat架构 使用docker部署nginx+tomcat架构():访问mysql数据库 不过, ...

  5. 使用docker部署nginx+tomcat架构(2):访问mysql数据库

    上一篇完成了通过docker部署nginx+tomcat的基础软件架构,但是距离一个真正可用的软件架构还差得很远.其中最重要的一点是缺少数据库这个角色的存在,那么本篇就来完善这一点. 废话少说,直接进 ...

  6. Docker | 部署nginx服务

    容器时相互隔离的,docker启动的nginx是容器内的服务,不影响我原先服务器上的nginx服务,小伙伴们可大胆尝试 本篇实在linux环境下操作的,主要目的是夺人眼目,对使用Docker部署服务尝 ...

  7. 【原创】大数据基础之Mesos+Marathon+Docker部署nginx

    一 安装 安装docker:https://www.cnblogs.com/barneywill/p/10343091.html安装mesos:https://www.cnblogs.com/barn ...

  8. docker 部署nginx 使用keepalived 部署高可用

    一.体系架构 在Keepalived + Nginx高可用负载均衡架构中,keepalived负责实现High-availability (HA) 功能控制前端机VIP(虚拟网络地址),当有设备发生故 ...

  9. docker 部署 nginx+php+mysql

    系统:centos7 使用root账户 开放80端口 firewall-cmd --zone=public --add-port=80/tcp --permanent 安装docker yum ins ...

随机推荐

  1. python: str()

    tx1 = '中国' tx2 = u'中国' print tx1 print tx2 print type(tx1) print type(tx2) #<type 'str'> str() ...

  2. 【Dubbo】带着问题看源码:什么是SPI机制?Dubbo是如何实现的?

    什么是SPI? ​ 在Java中,SPI全称为 Service Provider Interface,是一种典型的面向接口编程机制.定义通用接口,然后具体实现可以动态替换,和 IoC 有异曲同工之妙. ...

  3. SpringBoot(十四):SpringCloud初步认识

    SpringCloud是一个基于SpringBoot实现的云应用开发工具,它为开发人员提供了一些工具来快速构建分布式系统中的一些常见模式(例如配置管理.服务发现.断路器.智能路由.微代理.控制总线.一 ...

  4. 【Python】解析Python中的异常操作

    目录结构: contents structure [-] try,except,else,finally块 异常处理 使用except而不带任何异常类型 使用except而带多种异常类型 try-fi ...

  5. java上传图片并压缩图片大小

    Thumbnailator 是一个优秀的图片处理的Google开源Java类库.处理效果远比Java API的好.从API提供现有的图像文件和图像对象的类中简化了处理过程,两三行代码就能够从现有图片生 ...

  6. TortoiseSVN is locked in another working copy

    TortoiseSVN提交报错 TortoiseSVN is locked in another working copy原因:可能是因为打开了多个commit会话,然后又去修改了提交文件的内容,导致 ...

  7. nodejs命令行执行时带参数

    nodejs命令行执行时带参数 转 https://www.jianshu.com/p/474e6d76f867   今天项目里突然想在初始化时跑一些数据,于是想起以前在python时可以在命令行里带 ...

  8. Nginx warn:an upstream response is buffered to a temporary file

    我通过nginx下载文件,error.log中出现如下警告日志:warn:an upstream response is buffered to a temporary file  . 虽然网上各种例 ...

  9. Anaconda(三)

    五.TensorFlow安装 这一天由于版本问题走了太多弯路.之前用的conda版本是最新的,自带Python3.7.5,装了之后倒是各种包都能装,用命令: pip install xxx conda ...

  10. XML读写工具

    import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import j ...