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

上一篇:Nginx 容器挂载,发布vue项目
下一篇:Docker 常见问题

发表评论

最新留言

感谢大佬
[***.8.128.20]2025年04月19日 08时38分29秒