小工具知识网

当前位置: 首页 > 行业知识 > 【Docker】宝塔创建Docker容器配置nginx

行业知识

【Docker】宝塔创建Docker容器配置nginx

2026-11-12 21:25:09 来源:互联网转载

前言

本篇是我入门docker的第一篇,由于docker具有很好的移植性,易于安装,开箱即用;签约的公司项目开发需要我进行学习,否则money减半,5555~

百度找了一圈,只有关于docker怎么装宝塔服务器的却没有一篇宝塔中的docker装环境的,没办法只能自己探索了,有人会问为什么不使用Windows上的docker,我的电脑是win11,尝试装了装不上,于是使用服务器上的docker

创建容器

点击【创建容器】

拉取【nginx1.18】

容器命名为【test】

端口映射【3000->80】

1、拉取nginx是因为部署的项目时web环境,不清楚自己了解,除了nginx常用的还有apache

2、端口为什么需要映射,我的服务器已经占用了80端口,我通过防火墙规则开放一个端口例如:3000 访问它时让它指向docker容器的80端口

启动

这张图是我盗过来的,访问你的ip:3000打开如图说明docker部署nginx环境成功

部署h5项目

将项目移动至www/wwwroot里(注意:这里的目录是docker的目录,不是宝塔的,不知道docker目录可通过对容器操作跳转到目录路径)

修改nginx配置

路径:/var/lib/docker/*********/etc/nginx/conf.d

server {    listen       80;    listen  [::]:80;    server_name  localhost;    #charset koi8-r;    #access_log  /var/log/nginx/host.access.log  main;    location / {        root   /www/wwwroot/*******;        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   /www/wwwroot/*********;    }    # 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;    #}}

重启访问

最后

本次只是简单的介绍了docker如何拉取nginx部署h5项目,如果需要连接mysql、以及php等其他环境,后面再继续补充

上一篇:云服务器怎么加入?

下一篇:怎么服务器搭建数据库?