Docker反向代理Nginx Proxy Manager

不管是电信还是移动或其它的运营商,租用给我们的固定IP专线80和443端口都是被封掉了,所以在我们搭建好基于B/S架构的系统中,从远程访问总是采用IP+端口号的这种方式,使用起来很不方便,那么Nginx Proxy Manager可以实现反向代理,我们就可以使用正常的域名来访问,今天就向大家介绍一下Nginx Proxy Manager,官网地址:https://nginxproxymanager.com

一,准备工作

具体什么叫反向代理这里不做赘述,可以百度一下,采用Docker部署Nginx Proxy Manager,请做好如下准备工作

  • VPS服务器一台
  • 需要一个域名,目前国内需要备案,可以在国外注册后在cloudflare托管
  • 配置好Docker环境(详情可参考我的这篇文章:https://www.hao0564.com/1837.html
二,实操部署

Nginx Proxy Manager具体官方的Docker部署详情请见:https://github.com/NginxProxyManager/nginx-proxy-manager

  • 运行应用程序

创建一个docker-compose.yml文件:

version: "3"
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      # These ports are in format <host-port>:<container-port>
      - '80:80' # Public HTTP Port
      - '443:443' # Public HTTPS Port
      - '81:81' # Admin Web Port
      # Add any other Stream port you want to expose
      # - '21:21' # FTP

    # Uncomment the next line if you uncomment anything in the section
    # environment:
      # Uncomment this if you want to change the location of 
      # the SQLite DB file within the container
      # DB_SQLITE_FILE: "/data/database.sqlite"

      # Uncomment this if IPv6 is not enabled on your host
      # DISABLE_IPV6: 'true'

    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt

然后:

docker-compose up -d
  • 使用 MySQL / MariaDB 数据库

如果您选择 MySQL 配置,您必须自己提供数据库服务器。您也可以使用 MariaDB。以下是支持的最低版本:

  • MySQL v5.7.8+
  • MariaDB v10.2.7+

也很容易为您的数据库使用另一个 docker 容器并将其链接为 docker 堆栈的一部分,因此这就是以下示例将要使用的内容。

docker-compose.yml以下是使用 MariaDB 容器时的外观示例:

version: "3"
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      # These ports are in format <host-port>:<container-port>
      - '80:80' # Public HTTP Port
      - '443:443' # Public HTTPS Port
      - '81:81' # Admin Web Port
      # Add any other Stream port you want to expose
      # - '21:21' # FTP
    environment:
      DB_MYSQL_HOST: "db"
      DB_MYSQL_PORT: 3306
      DB_MYSQL_USER: "npm"
      DB_MYSQL_PASSWORD: "npm"
      DB_MYSQL_NAME: "npm"
      # Uncomment this if IPv6 is not enabled on your host
      # DISABLE_IPV6: 'true'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
    depends_on:
      - db

  db:
    image: 'jc21/mariadb-aria:latest'
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: 'npm'
      MYSQL_DATABASE: 'npm'
      MYSQL_USER: 'npm'
      MYSQL_PASSWORD: 'npm'
    volumes:
      - ./data/mysql:/var/lib/mysql

这里实操使用MySQL / MariaDB 数据库来部署,在使用docker-compose部署前,如果用于生产环境请修改账号和密码,例如

version: “3”
services:
app:
image: ‘jc21/nginx-proxy-manager:latest’
restart: unless-stopped
ports:
# These ports are in format :
– ’80:80′ # Public HTTP Port
– ‘443:443’ # Public HTTPS Port
– ’81:81′ # Admin Web Port
# Add any other Stream port you want to expose
# – ’21:21′ # FTP
environment:
DB_MYSQL_HOST: “db”
DB_MYSQL_PORT: 3306
DB_MYSQL_USER: “myzhangxiubing”
DB_MYSQL_PASSWORD: “myzhangxiubing”
DB_MYSQL_NAME: “myzhangxiubing”
# Uncomment this if IPv6 is not enabled on your host
# DISABLE_IPV6: ‘true’
volumes:

./data:/data
– ./letsencrypt:/etc/letsencrypt
depends_on:

– db

db:
image: ‘jc21/mariadb-aria:latest’

restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: ‘myzhangxiubing’
MYSQL_DATABASE: ‘myzhangxiubing’
MYSQL_USER: ‘myzhangxiubing’
MYSQL_PASSWORD: ‘myzhangxiubing’
volumes:
– ./data/mysql:/var/lib/mysql

警告

请注意,DB_MYSQL_*环境变量将优先于DB_SQLITE_*变量。因此,如果您保留 MySQL 变量,您将无法使用 SQLite。

  • 安装 Compose 
 sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
安装 Compose 
安装 Compose 

对二进制文件应用可执行权限:

$ sudo chmod +x /usr/local/bin/docker-compose
安装 Compose 
安装 Compose 

测试安装

$ docker-compose --version

[root@localhost ~]# docker-compose –version
docker-compose version 1.29.2, build 5becea4c

测试安装
测试安装
  • docker-compose部署ginx Proxy Manager

[root@localhost ~]# mkdir /root/portainer_data

[root@localhost portainer_data]# touch docker-compose.yml

[root@localhost portainer_data]# vi docker-compose.yml

docker-compose部署ginx Proxy Manager
docker-compose部署Nginx Proxy Manager

[root@localhost portainer_data]# docker-compose up -d

docker-compose部署ginx Proxy Mana
docker-compose部署Nginx Proxy Manager

安装成功后,访问Nginx Proxy Manager IP+端口号81

访问Nginx Proxy Manager
访问Nginx Proxy Manager
默认管理员用户
Email:    admin@example.com
Password: changeme
Nginx Proxy Manager
Nginx Proxy Manager
Nginx Proxy Manager
Nginx Proxy Manager

一条评论

留下评论

您的邮箱地址不会被公开。 必填项已用 * 标注