摘要:本文将带你了解Vmware之在docker运行nginx,希望本文对大家学Vmware有所帮助。
本文将带你了解Vmware之在docker运行nginx,希望本文对大家学Vmware有所帮助。
docker:在docker运行nginx
目标:通过docker运行nginx
前提:了解nginx的基本用法,了解docker基本指令
step1:宿主机准备
root@c-pc:/opt/docker_nginx# docker pull nginx
...
root@c-pc:/opt/docker_nginx# ls
conf log www
conf存放nginx的配置文件,log存放nginx的日志,www存放模板文件,见下图
root@c-pc:/opt/docker_nginx# tree
.
├── conf
│ └── nginx.conf
├── log
│ ├── access.log
│ └── error.log
└── www
└── index.html
以下是nginx.conf内容
user www-data;
worker_processes auto;
pid /run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# SSL Settings
##
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;
##
# Logging Settings
##
access_log /opt/nginx/log/access.log;
error_log /opt/nginx/log/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
##
# Virtual Host Configs
##
server {
listen 80 default_server;
listen [::]:80 default_server;
root /opt/nginx/www;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
}
}
}
以上这个配置从nginx的默认配置文件复制出来的,改动log、root相关内容,即:
...
access_log /opt/nginx/log/access.log;
error_log /opt/nginx/log/error.log;
...
root /opt/nginx/www;
...
index.html
Hello docker nginx
step2:
启动容器
root@c-pc:/opt/docker_nginx# docker run -p 8093:80 --name mynginx -v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf -v $PWD/www:/opt/nginx/www -v $PWD/log:/opt/nginx/log -d nginx
026f7dc3dfa4362210a5273775e01222c6b622a9298ec20e9d53f46d9bc72f20
命令说明:
-p 8093:80:将容器的80端口映射到主机的8093端口
-name mynginx:将容器命名为mynginx
-v $PWD/conf/nginx.conf:/etc/nginx/nginx.conf:将主机中当前目录下的nginx.conf挂载到容器的/etc/nginx/nginx.conf
-v $PWD/www:/opt/nginx/www:将主机中当前目录下的www挂载到容器的/opt/nginx/www,参考nginx.conf的root配置
-v $PWD/log:/opt/nginx/log:将主机中当前目录下的log挂载到容器的/opt/nginx/log,参考nginx.conf的log配置
step3:测试是否正常
在主机浏览器打开
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标系统运维之Vmware频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号