分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

使用Docker构建nginx静态网站

发布时间:2023-09-06 02:32责任编辑:董明明关键词:nginxDocker

1. 建Dockerfile:

FROM ubuntu:14.04MAINTAINER Marc LAW "zunly@hotmail.com"ENV REFRESHED_AT 2019-02-03RUN apt-get -yqq update && apt-get -yqq install nginxRUN mkdir -p /var/www/html/websiteADD nginx/global.conf /etc/nginx/conf.d/ADD nginx/nginx.conf /etc/nginx/nginx.confEXPOSE 80

从ubuntu中拉取nginx

2. global.conf跟nginx.conf文件:

[m@localhost NginxWebSite]$ cat nginx/nginx.conf user www-data;worker_processes 4;pid /run/nginx.pid;daemon off;events { ?}http { ?sendfile on; ?tcp_nopush on; ?tcp_nodelay on; ?keepalive_timeout 65; ?types_hash_max_size 2048; ?include /etc/nginx/mime.types; ?default_type application/octet-stream; ?access_log /var/log/nginx/access.log; ?error_log /var/log/nginx/error.log; ?gzip on; ?gzip_disable "msie6"; ?include /etc/nginx/conf.d/*.conf;}
[m@localhost NginxWebSite]$ cat nginx/global.conf server { ???????listen ?????????0.0.0.0:80; ???????server_name ????_; ???????root ???????????/var/www/html/website; ???????index ??????????index.html index.htm; ???????access_log ?????/var/log/nginx/default_access.log; ???????error_log ??????/var/log/nginx/default_error.log;}

3. 构建镜像:

$ sudo docker build -t jamtur01/nginx .

4. 启动镜像:

$ sudo docker run -d -p 80 --name website -v $PWD/website:/var/www/html/website jamtur01/nginx nginx

-v 命令把宿主机的$PWD/website目录映射到容器内的nginx的html根目录.

5. 关掉selinux, 在$PWD/website里面建index.html文件, 并根据容器的映射端口(随机)测试访问吧.

使用Docker构建nginx静态网站

原文地址:https://www.cnblogs.com/Montauk/p/10351265.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved