
Docker Nginx服务器部署简单静态网页
发布日期:2021-05-07 00:07:44
浏览次数:27
分类:精选文章
本文共 1681 字,大约阅读时间需要 5 分钟。
一、拉取Nginx镜像
通过运行以下命令可以拉取Nginx镜像: `docker pull nginx`如果需要自定义镜像,可以使用Dockerfile构建:
docker build -t nginx .
二、服务器架构
启动Nginx容器并映射端口: `docker run -d -p 80:80 nginx`检查容器状态:
docker ps
输出示例:CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5e4ec9513915 nginx "/docker-entrypoint.…" 5 seconds ago Up 4 seconds 0.0.0.0:80->80/tcp nice_yalow
进入容器:
docker exec -i -t 5e4ec9513915 /bin/bash
查看Nginx配置:
cat /etc/nginx/conf.d/default.conf
配置内容如下: server { listen 80; listen [::]:80; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/host.access.log main; location / { root /usr/share/nginx/html; index index.html index.htm; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # # proxy_pass http://127.0.0.1; # #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # # root html; # # fastcgi_pass 127.0.0.1:9000; # # fastcgi_index index.php; # # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # # include fastcgi_params; # #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # # deny all; # #}
三、部署项目
将`index.html`和背景图片复制到Nginx容器: `docker cp index.html 5e4ec9513915:/usr/share/nginx/html`访问服务器地址:
http://localhost:80
发表评论
最新留言
感谢大佬
[***.8.128.20]2025年04月19日 08时38分29秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
linux 根目录扩容
2023-02-01
linux 添加微软字体,如何给Ubuntu添加Windows及Mac字体?
2023-02-01
linux 添加本地yum源
2023-02-01
LINUX 游戏服务器之旅4_mongodb环境
2023-02-01
linux 源码搭建lnmp_Linux源码安装lnmp
2023-02-01
Linux 环境下将 ASM 磁盘映射到物理磁盘的完整指南
2023-02-01
Linux 环境下更新 Python
2023-02-01
Linux 用户和用户组管理
2023-02-01
Linux 用户被差别对待?无法通过 apple.com 管理 Apple ID
2023-02-01
linux 登录后佛祖保佑
2023-02-01
Linux 的 cat 命令居然有那么多门道,涨知识了!
2023-02-01
Linux 的NFS服务的配置
2023-02-01
linux 的vi vim 的常用的基本命令
2023-02-01
Linux 的性能调优的思路
2023-02-01
Linux 的文本搜索命令 grep
2023-02-01
Linux 的账号与群组管理
2023-02-01
linux 目录&基础命令
2023-02-01