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 是前后端分离的项目,除了后端微服务的部署之外,当然还少不了前端工程的部署.所以本篇讲 ...
随机推荐
- 索引与查询使用的 collate 不一致导致无法使用索引
索引与表的collate 不一致的情况下,会导致表上的索引不可用,这时要想使用索引,必须在SQL 语句指定建索引所用的collate. 数据库默认collate : test=# \l List of ...
- Android开发 活动activity
一.关于Activity 关于Activity必须要了解的内容有:Activity的生命周期.android任务栈.Activity启动模式.scheme跳转协议. 1.1 什么是Activity ...
- ssh登录太慢了,每次都要20s
背景 大家工作时,少不了ssh登录各个服务器,我这边手里也有很多服务器,有一些登录很快就进去了,有些要卡半天才能进去.之前以为是公司网络问题,每次也就忍了,这次突然不想忍了,决定定位一下. 我这边的服 ...
- 02 jQuery选择器
02 jQuery选择器 jQuery的逻辑和css选择器的逻辑是一样的. // 语法: $(选择器) 可以使用jQuery选择器快速的对页面结构进行操作. 案例: <!DOCTYPE html ...
- #团,构造#洛谷 3524 [POI2011]IMP-Party
题目 有一个 \(3n\) 个点的无向图,保证有一个大小为 \(2n\) 的团,输出一个大小为 \(n\) 的团 分析 每次选择两个不相连的点删掉,那么剩下的 \(n\) 个点一定是团, 因为每次至少 ...
- #直径#CF804D Expected diameter of a tree
题目 给一片森林,\(q\) 个询问,每个询问两个点, 问将这两个点所在的集合连接起来组成的新集合,它的最远两点的距离的期望值是多少. 分析 首先将以每个点为根的最大深度求出来,然后对于两棵树, 只有 ...
- IntelliJ IDEA 配置类注释模板
菜单栏依次点击 File > Settings 在弹出窗口中找到 Editor >File and Code Templates 在右侧中 Files 选项卡中找到 Class. 在右侧输 ...
- linux 性能自我学习 ———— cpu 快速定位问题 [六]
前言 主要介绍一下cpu如何快速定位问题. 正文 cpu 的一些性能指标: 1. cpu 使用率 cpu 使用率描述了非空闲时间占总cpu时间的百分比,根据cpu上运行任务的不同,又被分为用户cpu. ...
- 吴恩达机器学习课后作业ex1
题目大体意思就是输入的是某地的人口,输出的是某地方的收益. 题目及数据集下载: https://wwa.lanzous.com/b054sprza 密码:ba3w 大体模型如下图:现在X前边加一列值为 ...
- 前端使用 Konva 实现可视化设计器(5)
关于第三章提到的 selectingNodesArea,在后续的实现中已经精简掉了. 而 transformer 的 dragBoundFunc 中的逻辑,也直接移动 transformer 的 dr ...