docker 安装nginx 配置目录挂载
nginx 的安装
mkdir /usr/local/docker
cd /usr/local/docker
docker run --name nginxtest -d nginx #运行一个测试的nginx
docker cp nginxtest:/etc/nginx ./ #把容器里的nginx的目录复制
docker rm -f nginxtest #删除测试的nginx-test
复制出来的nginx目录结构
#复制出来的nginx目录结构
[root@localhost docker]# tree nginx
nginx
├── conf.d
│ └── default.conf
├── fastcgi_params
├── koi-utf
├── koi-win
├── logs
│ ├── access.log
│ ├── error.log
│ ├── gin.haimait.com.access.log
│ ├── gin.haimait.com.error.log
│ ├── localhost.access.log
│ └── localhost.error.log
├── mime.types
├── modules -> /usr/lib/nginx/modules
├── nginx.conf
├── scgi_params
├── uwsgi_params
└── win-utf
运行mynginx容器
#运行mynginx 挂载到/wwwroot是为了保持容器和宿主机目录一致,以免配置时出错
docker run \
--name mynginx \
-p 8081:80 \
-p 443:443 \
-v /etc/localtime:/etc/localtime:ro \
-v /wwwroot:/wwwroot \
-v $PWD/nginx:/etc/nginx \
-v $PWD/nginx/logs:/var/log/nginx \
--restart always \
-d nginx
编写默认的配置文件
vim $PWD/nginx/conf.d/default.conf
把内容换下面的内容
server {
listen 80;
server_name localhost;
access_log /var/log/nginx/localhost.access.log;
error_log /var/log/nginx/localhost.error.log;
# 配置前端静态文件目录
location / {
root /wwwroot/html;
index index.html index.htm index.php;
}
#location ~ \.php$ {
# fastcgi_pass myphp73-fpm:9000; #myphp73-fpm容器的名字
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# include fastcgi_params;
#}
# 配置后台go服务api接口服务 代理到8877端口
#location ~ ^/goadminapi/ {
# proxy_set_header Host $http_host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# rewrite ^/goadminapi/(.*)$ /$1 break;
# proxy_pass http://127.0.0.1:8877;
# }
}
配置一个域名也指向到/wwwroot/html目录 确定你的域名已经解析到服务器的ip上了
vim $PWD/nginx/conf.d/gin.haimait.com.conf
内容如下:
server {
listen 80;
server_name gin.haimait.com;
access_log /var/log/nginx/gin.haimait.com.access.log;
error_log /var/log/nginx/gin.haimait.com.error.log;
# 配置前端静态文件目录
location / {
root /wwwroot/html;
index index.html index.htm index.php;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
#location ~ \.php$ {
# fastcgi_pass myphp73-fpm:9000; #myphp73-fpm容器的名字
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# include fastcgi_params;
#}
# 配置后台go服务api接口服务 代理到8877端口
#location ~ ^/goadminapi/ {
# proxy_set_header Host $http_host;
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto $scheme;
# rewrite ^/goadminapi/(.*)$ /$1 break;
# proxy_pass http://127.0.0.1:8877;
# }
}
重启nginx
docker restart mynginx
新建index.html
mkdir /wwwroot/html
vim /wwwroot/html/index.html
内容如下:
hello nginx , html
测试
以下说明都已经配置成功了
[root@localhost ~]# curl localhost:8081
hello nginx , html
[root@localhost ~]# curl gin.haimait.com:8081
hello nginx , html
浏览器访问

删除nginx容器重启容器,wwwroot里的内容也不会丢
到此已经完成安装
设置开机自动启动容器
在运行docker容器时可以加如下参数来保证每次docker服务重启后容器也自动重启:
docker run --restart=always CONTAINER ID
如果已经启动了则可以使用如下命令:
docker update --restart=always CONTAINER ID #设置启动nginx时自动启动
docker update --restart=no CONTAINER ID #设置启动nginx时不启动
[root@localhost www]# docker update --restart=always nginx
nginx
docker 安装nginx 配置目录挂载的更多相关文章
- docker安装MySQL8,目录挂载、配置用户名密码、忽略表名大小写、连接数、特殊字符、时区
原文:docker安装MySQL8,目录挂载.配置用户名密码.忽略表名大小写.连接数.特殊字符.时区 一.环境配置 1.系统:centos7.3 2.docker版本:Docker version 1 ...
- Linux docker 安装nginx 配置ssl证书
Linux docker 安装nginx 配置ssl证书 如果觉得样式不好:跳转即可 md文件复制过来有些样式会不一样) 原文地址:https://lifengying.site/archives/b ...
- 【转载】Docker 安装 Nginx 并个性化挂载配置文件 nginx.conf
首先,系统(3.8以上内核的linux)中安装好 Docker 这个运用程序.由于网络原因,我们下载一个Docker官方的镜像需要很长的时间,甚至下载失败.为此,阿里云容器镜像服务提供了官方的镜像站点 ...
- docker安装nginx并配置通过https访问
1. 下载最新的nginx的docker image docker pull nginx:latest 创建挂载路径 2.准备nginx需要的文件 nginx的配置文件 首先是nginx.conf文件 ...
- docker安装和配置nginx
配置nginx docker配置nginx 本机ip是192.168.0.200 docker pull nginx 配置nginx主机 vi /root/docker/nginx/nginx01.c ...
- 阿里云CentOS7.3服务器通过Docker安装Nginx
前言 小编环境: 阿里云CentOS7.3服务器 docker 下面分享一次小编在自己的阿里云CentOS7.3服务器上使用Docker来安装Nginx的一次全过程 温馨小提示: 如果只是希望单纯使用 ...
- Ubuntu Docker 安装和配置 GitLab CI 持续集成
相关文章: Ubuntu Docker 简单安装 GitLab 劈荆斩棘:Gitlab 部署 CI 持续集成 目的:在 Ubuntu 服务器上,使用 Docker 安装和配置 GitLab Runne ...
- Linux、Docker安装Nginx
Docker安装Nginx #docker images nginx #docker search nginx #docker pull nginx #docker run -it -p 8084:8 ...
- centos7下使用docker安装nginx
需要环境docker,此处不做介绍. 1. docker拉取官方nginx镜像 docker pull nginx 2. 等待下载完成后,我们就可以在本地镜像列表里查到 REPOSITORY 为 ng ...
- Docker实战 | 第三篇:Docker安装Nginx,实现基于vue-element-admin框架构建的项目线上部署
一. 前言 在上一文中 点击跳转 通过IDEA集成Docker插件实现微服务的一键部署,但 youlai-mall 是前后端分离的项目,除了后端微服务的部署之外,当然还少不了前端工程的部署.所以本篇讲 ...
随机推荐
- https安全性 带给im 消息加密的启发
大家好,我是蓝胖子,在之前# MYSQL 是如何保证binlog 和redo log同时提交的?这篇文章里,我们可以从mysql的设计中学会如何让两个服务的调用逻辑达到最终一致性,这也是分布式事务实现 ...
- #线性基#CF1100F Ivan and Burgers
题目传送门 分析 线段树上直接维护线性基是三个log的.(一定要合并) 考虑一种分治做法,在 \([l,mid]\) 和 \((mid,r]\) 的询问分治处理, 跨过 \([mid,mid+1]\) ...
- #容斥#51nod 1407 与与与与
题目 给出 \(n\) 个数,问有多少个子集的按位与为0 分析 考虑容斥,设 \(f[i]\) 表示有多少个数按位与为 \(x\),满足 \(x\&i=i\) 那么答案就是 \(\sum_{i ...
- #二分图匹配#洛谷 5771 [JSOI2016]反质数序列
题目 给出 \(n\) 个正整数,问最大的子集使得任意两个数的和都不是质数 \(n\leq 3*10^3\) 分析 如果把两个数的和为质数连边,等价于求最大独立集. 由于只有偶数加奇数才可能产生质数( ...
- JDK14性能管理工具:jstat使用介绍
目录 简介 JStat命令 JStat Output Options class compiler gc gccapacity gcnew gcnewcapacity gcold gcoldcapac ...
- OpenHarmony 3.2 Beta源码分析之MediaLibrary
1.MediaLibrary介绍 OpenAtom OpenHarmony(以下简称"OpenHarmony")MediaLibrary媒体库提供了一系列易用的接口用于获取媒体文件 ...
- Docker学习路线6:使用第三方镜像
第三方镜像是在Docker Hub或其他容器注册表上提供的预构建Docker容器镜像.这些镜像由个人或组织创建和维护,可以作为您容器化应用程序的起点. 查找第三方镜像 Docker Hub 是最大和最 ...
- Docker学习路线5:在 Docker 中实现数据持久化
Docker 可以运行隔离的容器,包括应用程序和其依赖项,与主机操作系统分离.默认情况下,容器是临时的,这意味着容器中存储的任何数据在终止后都将丢失.为了解决这个问题并在容器生命周期内保留数据,Doc ...
- signalr 应用于微信小程序(一)
前言 在2017年基于signalr 和微信小程序 写的脚本. 正文 先安装signalr: 1.安装singalr,用nutget就行,用这个包管理就行. 2.使用singalr 3.根据singa ...
- Phoenix 时区问题
最近在测试flink从trino查询数据插入到phoenix5的功能,发现一个时间的问题: 明明插入的时间是 '1940-06-01',查询出来的时间会少一天,同样的 Timestamp 也会自动少掉 ...