【打工日常】Docker部署一款开源免费的nginx-web管理

一、项目介绍

    1.项目简述
    Nginx Proxy Manager是一款基于web页面管理nginx的工具,可以便于对nginx的反向代理、ssl证书进行快捷操作,对服务的代理、重定向、访问限制等功能有一个清晰简单的页面。
    
    2.项目功能
    基于Tabler的美观安全的管理界面;轻松创建转发域、重定向、流和404主机;自定义管理SSL证书;主机的访问列表和基本HTTP身份验证;高级Nginx配置可供超级用户使用;用户管理、权限和审核日志。

    3.项目开源地址
    https://nginxproxymanager.com/guide/#quick-setup
    

----------

二、项目搭建环境

    1. 项目测试环境

    A.项目搭建在腾讯云centos7.6,外网地址为43.138.153.157
    Linux VM-8-12-centos 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

    B.docker版本为26.01,docker-compose版本为v2.26.1
    注意:本次实践部署环境为个人腾讯云的测试环境,若是生产环境请谨慎部署;对应开启了容器的端口,在linux下和防火墙下需开放对应端口。
    
    2. 本次项目实施过程
    
    使用docker下载镜像,创建好项目需要挂载的路径,通过docker-cli或者docker compose启动容器,启动容器后查看容器启动状态,查看容器的运行日志是否正常,以上全部正常执行后体验项目功能。

    3.注意:docker下载镜像有可能遇到比较慢的情况,参考以下解决措施:
    
    A.docker配置换源,进入/etc/docker的路径,如果没有就创建这个目录
    cd /etc/docker/
    mkdir -p /etc/docker
    
    B.编辑配置文件
    vim daemon.json   ##可以清空里面的内容:%d 然后复制下面的源进去wq保存
    
    {
        "registry-mirrors":[
            "https://286u3d9d.mirror.aliyuncs.com"
        ]
    }
    
    C.registry-mirrors:指定了一个镜像仓库的 URL https://286u3d9d.mirror.aliyuncs.com。 这个配置项用于设置 Docker镜像的镜像仓库地址,使得在拉取和推送 Docker 镜像时能够通过该镜像仓库进行加速。这边提供的是广东广州服务器的镜源,建议个人自己去阿里云建一个个人账号,根据实际所在区获取镜源。
    
    D.重新加载源,重启docker服务
    sudo systemctl daemon-reload 
    sudo systemctl restart docker

----------


三、项目搭建前巡检

    1. 检查docker是否正常运行
    systemctl status docker
    or
    service docker status
    注:我个人测试环境是使用systemctl进行管理,若有使用service管理请使用第二条的命令进行查看。   
    
    [root@VM-8-12-centos ~]# systemctl status docker
    ● docker.service - Docker Application Container Engine
       Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
       Active: active (running) since Mon 2024-04-22 23:13:57 CST; 4 days ago
         Docs: https://docs.docker.com
     Main PID: 17092 (dockerd)
        Tasks: 158
       Memory: 142.3M
       CGroup: /system.slice/docker.service

    若显示docker的Active是active (running),即表明docker是正常运行的。

    2.一般我会使用docker-compose去管理,所以预先需要创建好yaml文件,vim docker-compose.yml,格式如下例子:

    version: '3.9'
    services:
        nginx:
            image: nginx
            logging:
                options:
                    max-size: 1g
            restart: always
            volumes:
                - '/var/run/docker.sock:/tmp/docker.sock:ro'
            ports:
                - '80:80'

----------


四、项目实施过程

    1.根据开源项目,找到对应的镜像进行pull,若遇到很慢的情况,先检查是否网络问题以及是否已经换源。
    docker pull jc21/nginx-proxy-manager:latest

    [root@VM-8-12-centos ~]# docker pull jc21/nginx-proxy-manager:latest
    latest: Pulling from jc21/nginx-proxy-manager
    72a69066d2fe: Already exists
    825188956e90: Pull complete
    6916d26329a2: Pull complete
    c38d769b409b: Pull complete
    1f80df406181: Pull complete
    0f08d5fe2388: Pull complete
    8c6f29f06fbf: Pull complete
    842e56434587: Pull complete
    59b65e9e8c19: Pull complete
    2fa90c56d9cd: Pull complete
    c34ae494dda2: Pull complete
    596a4287c95c: Pull complete
    93fed03147ec: Pull complete
    06e5cea7a2e8: Pull complete
    ed7b32089832: Pull complete
    3645a0fd7712: Pull complete
    3fc06797edcf: Pull complete
    21b8ccd554d9: Pull complete
    f1e42dc354f3: Pull complete
    d2d267cd8da3: Pull complete
    cdb75b136b21: Pull complete
    9274cd10b66f: Pull complete
    ea2bd62b2698: Pull complete
    b205e981c16a: Pull complete
    0dafef540f92: Pull complete
    8cc9fc813fd3: Pull complete
    Digest: sha256:e6d13908c87d150efc1566a9ed1570661f1c3e09362b26bfe7d7608a831e4591
    Status: Downloaded newer image for jc21/nginx-proxy-manager:latest
    docker.io/jc21/nginx-proxy-manager:latest

    2.若已经下载完成显示新的一行,可以输入命令查看是否上一条命令执行成功
    echo$?
    若返回0,则成功;返回其他则根据实际情况重新下载或者查找原因。

    3.docker下载完后,可以查看对应的镜像是否下载成功
    docker images |grep jc21/nginx-proxy-manager
    
    [root@VM-8-12-centos nginx-manager]# docker images |grep jc21/nginx-proxy-manager
    jc21/nginx-proxy-manager     latest      1d0ce4696d69   2 years ago     868MB
     
    4.下载成功后,先创建文件夹存放data以及yml文件,然后编辑docker-compose.yml文件
    
    mkdir -p /opt/nginx-manager
    cd /opt/nginx-manager
    vim docker-compose.yml
    
    version: '3'
    services:
      app:
        image: 'jc21/nginx-proxy-manager:latest'
        restart: unless-stopped
        ports:
          - '80:80'
          - '81:81'
          - '443:443'
        volumes:
          - ./data:/data
          - ./letsencrypt:/etc/letsencrypt

    编辑后输入wq进行保存
        
    5.为了便捷启动,也可以使用docker-cli启动
    
    mkdir -p /opt/nginx-manager
    cd /opt/nginx-manager
        
    docker run --name app -d -p 80:80 -p 81:81 -p 443:443 -v ./data:/data -v ./letsencrypt:/etc/letsencrypt jc21/nginx-proxy-manager:latest

    6.启动docker-compose

    docker compose up -d  
    
    7.启动容器后,查看容器的状态是否正常  
    
    docker compose ps
        
    [root@VM-8-12-centos nginx-manager]# docker compose ps
    NAME                  IMAGE                             COMMAND   SERVICE   CREATED          STATUS          PORTS
    nginx-manager-app-1   jc21/nginx-proxy-manager:latest   "/init"   app       19 minutes ago   Up 19 minutes   0.0.0.0:80-81->80-81/tcp, :::80-81->80-81/tcp, 0.0.0.0:443->443/tcp, :::443->443/tcp
    
    8.启动容器后,查看容器的日志是否正常
    
    docker logs -f nginx-manager-app-1
    
    [root@VM-8-12-centos nginx-manager]# docker logs -f nginx-manager-app-1
    [s6-init] making user provided files available at /var/run/s6/etc...exited 0.
    [s6-init] ensuring user provided files have correct perms...exited 0.
    [fix-attrs.d] applying ownership & permissions fixes...
    [fix-attrs.d] done.
    [cont-init.d] executing container initialization scripts...
    [cont-init.d] 01_perms.sh: executing... 
    Changing ownership of /data/logs to 0:0
    [cont-init.d] 01_perms.sh: exited 0.
    [cont-init.d] 01_s6-secret-init.sh: executing... 
    [cont-init.d] 01_s6-secret-init.sh: exited 0.
    [cont-init.d] done.
    [services.d] starting services
    [services.d] done.
    Generating dummy SSL certificate...
    Generating a RSA private key
    ..................+++++
    ......+++++
    writing new private key to '/data/nginx/dummykey.pem'
    -----
    Complete
    ❯ Enabling IPV6 in hosts: /etc/nginx/conf.d
      ❯ /etc/nginx/conf.d/production.conf
      ❯ /etc/nginx/conf.d/default.conf
      ❯ /etc/nginx/conf.d/include/ip_ranges.conf
      ❯ /etc/nginx/conf.d/include/force-ssl.conf
      ❯ /etc/nginx/conf.d/include/proxy.conf
      ❯ /etc/nginx/conf.d/include/letsencrypt-acme-challenge.conf
      ❯ /etc/nginx/conf.d/include/assets.conf
      ❯ /etc/nginx/conf.d/include/block-exploits.conf
      ❯ /etc/nginx/conf.d/include/ssl-ciphers.conf
      ❯ /etc/nginx/conf.d/include/resolvers.conf
    ❯ Enabling IPV6 in hosts: /data/nginx
    [5/21/2024] [8:28:02 AM] [Global   ] › ℹ  info      No valid environment variables for database provided, using default SQLite file '/data/database.sqlite'
    [5/21/2024] [8:28:02 AM] [Global   ] › ℹ  info      Generating SQLite knex configuration
    [5/21/2024] [8:28:02 AM] [Global   ] › ⬤  debug     Wrote db configuration to config file: ./config/production.json
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      Current database version: none
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [initial-schema] Migrating Up...
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [initial-schema] auth Table created
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [initial-schema] user Table created
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [initial-schema] user_permission Table created
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [initial-schema] proxy_host Table created
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [initial-schema] redirection_host Table created
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [initial-schema] dead_host Table created
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [initial-schema] stream Table created
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [initial-schema] access_list Table created
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [initial-schema] certificate Table created
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [initial-schema] access_list_auth Table created
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [initial-schema] audit_log Table created
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [websockets] Migrating Up...
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [websockets] proxy_host Table altered
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [forward_host] Migrating Up...
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [forward_host] proxy_host Table altered
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [http2_support] Migrating Up...
    [5/21/2024] [8:28:02 AM] [Migrate  ] › ℹ  info      [http2_support] proxy_host Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [http2_support] redirection_host Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [http2_support] dead_host Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [forward_scheme] Migrating Up...
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [forward_scheme] proxy_host Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [disabled] Migrating Up...
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [disabled] proxy_host Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [disabled] redirection_host Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [disabled] dead_host Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [disabled] stream Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [custom_locations] Migrating Up...
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [custom_locations] proxy_host Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [hsts] Migrating Up...
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [hsts] proxy_host Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [hsts] redirection_host Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [hsts] dead_host Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [settings] Migrating Up...
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [settings] setting Table created
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [access_list_client] Migrating Up...
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [access_list_client] access_list_client Table created
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [access_list_client] access_list Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [access_list_client_fix] Migrating Up...
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [access_list_client_fix] access_list Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [pass_auth] Migrating Up...
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [pass_auth] access_list Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [redirection_scheme] Migrating Up...
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [redirection_scheme] redirection_host Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [redirection_status_code] Migrating Up...
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [redirection_status_code] redirection_host Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [stream_domain] Migrating Up...
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [stream_domain] stream Table altered
    [5/21/2024] [8:28:03 AM] [Migrate  ] › ℹ  info      [stream_domain] Migrating Up...
    [5/21/2024] [8:28:03 AM] [Setup    ] › ℹ  info      Creating a new JWT key pair...
    [5/21/2024] [8:28:05 AM] [Setup    ] › ℹ  info      Wrote JWT key pair to config file: /app/config/production.json
    [5/21/2024] [8:28:05 AM] [Setup    ] › ℹ  info      Creating a new user: admin@example.com with password: changeme
    [5/21/2024] [8:28:06 AM] [Setup    ] › ℹ  info      Initial admin setup completed
    [5/21/2024] [8:28:06 AM] [Setup    ] › ℹ  info      Default settings added
    [5/21/2024] [8:28:06 AM] [Setup    ] › ℹ  info      Logrotate Timer initialized
    [5/21/2024] [8:28:06 AM] [Setup    ] › ℹ  info      Logrotate completed.
    [5/21/2024] [8:28:06 AM] [IP Ranges] › ℹ  info      Fetching IP Ranges from online services...
    [5/21/2024] [8:28:06 AM] [IP Ranges] › ℹ  info      Fetching https://ip-ranges.amazonaws.com/ip-ranges.json
    [5/21/2024] [8:28:08 AM] [IP Ranges] › ℹ  info      Fetching https://www.cloudflare.com/ips-v4
    [5/21/2024] [8:28:08 AM] [IP Ranges] › ℹ  info      Fetching https://www.cloudflare.com/ips-v6
    [5/21/2024] [8:28:09 AM] [SSL      ] › ℹ  info      Let's Encrypt Renewal Timer initialized
    [5/21/2024] [8:28:09 AM] [SSL      ] › ℹ  info      Renewing SSL certs close to expiry...
    [5/21/2024] [8:28:09 AM] [IP Ranges] › ℹ  info      IP Ranges Renewal Timer initialized
    [5/21/2024] [8:28:09 AM] [Global   ] › ℹ  info      Backend PID 242 listening on port 3000 ...
    [5/21/2024] [8:28:09 AM] [Nginx    ] › ℹ  info      Reloading Nginx
    [5/21/2024] [8:28:09 AM] [SSL      ] › ℹ  info      Renew Complete
    `QueryBuilder#allowEager` method is deprecated. You should use `allowGraph` instead. `allowEager` method will be removed in 3.0
    `QueryBuilder#eager` method is deprecated. You should use the `withGraphFetched` method instead. `eager` method will be removed in 3.0
    QueryBuilder#omit is deprecated. This method will be removed in version 3.0
    Model#$omit is deprected and will be removed in 3.0.

----------


五、项目体验

    注:云服务器记得放开防火墙!
    访问地址https://43.138.153.157:81/,欢迎点击玩一下!账号test@example.com,密码111111111
    更多好玩有趣有用的内容,请关注微信公众号:零氪的云原生


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Docker是一种开源的容器化平台,可轻松部署、运行和管理容器化应用程序。Nginx一款高性能的Web服务器和反向代理服务器,而Nginx Proxy Manager则是一个基于Nginx的图形化界面工具,用于管理Nginx代理服务器。 要在Docker部署Nginx Proxy Manager,需要执行以下步骤: 1. 首先,确保你的系统上已安装了Docker。你可以通过命令"docker --version"来检查是否已成功安装。 2. 打开终端或命令提示符,并使用Docker命令从Docker Hub下载Nginx Proxy Manager的镜像。可以使用以下命令下载并创建容器: ``` docker run -d -p 80:80 -p 81:81 -p 443:443 -v nginx-proxy-manager_data:/data -v /var/run/docker.sock:/var/run/docker.sock jlesage/nginx-proxy-manager ``` 3. 这个命令会从Docker Hub上下载最新版本的Nginx Proxy Manager镜像,并在本地创建一个名为"nginx-proxy-manager"的容器。该容器将监听80、81和443端口,并将其映射到宿主机上。 此外,该命令还将容器中的/data目录映射到名为nginx-proxy-manager_data的Docker卷,以及将宿主机的/var/run/docker.sock文件映射到容器的/var/run/docker.sock文件中。 4. 当容器成功创建后,你可以通过访问http://localhost:81来访问Nginx Proxy Manager的图形化界面。在该界面中,你可以添加和管理Nginx反向代理服务器、创建和编辑主机、设置SSL证书等。 通过以上几个简单的步骤,你可以在Docker中轻松地部署Nginx Proxy Manager,实现代理服务器的管理与配置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

全糖去冰吃不了苦

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值