---
title: "部署 Nginx 代理 - 开发者中心 ODC V4.2.0 | OceanBase 文档中心"
description: 部署 Nginx 代理 在所有节点均完成部署 OceanBase 开发者中心（OceanBase Developer Center，ODC）镜像后，需在其中一个 ODC 节点上部署一个 Nginx 代理，通过 Nginx 将用户请求路由到不同的节点应用上。部署 Nginx 代理需在一个节点上拉取并运行 Nginx 镜…
---
切换语言

- 中文站 - 简体中文
- International - English
- 日本站 - 日本語

文档反馈![](https://mdn.alipayobjects.com/huamei_22khvb/afts/img/A*lqS5SYzz_YEAAAAAAAAAAAAADiGDAQ/original) 开发者中心 ODCV 4.2.0

# 部署 Nginx 代理

更新时间：2026-04-13 14:20:55

[编辑](https://github.com/oceanbase/odc-doc/edit/V4.2.0/zh-CN/1100.deployment-guide/400.deploy-the-ha-odc/400.deploy-nginx-proxy.md)  

在所有节点均完成部署 OceanBase 开发者中心（OceanBase Developer Center，ODC）镜像后，需在其中一个 ODC 节点上部署一个 Nginx 代理，通过 Nginx 将用户请求路由到不同的节点应用上。部署 Nginx 代理需在一个节点上拉取并运行 Nginx 镜像，运行后将配置文件拷贝到本地进行修改，在本地修改完配置文件后，先停运 Nginx 镜像再重启镜像以应用修改后的配置的文件。

## 加载镜像

选择一个节点加载并运行 Nginx 镜像，目前镜像可通过两种方式获得：

- 在宿主机上从 Docker 仓库中直接拉取镜像。
 - 下载镜像包到本地，再拷贝至宿主机中解压。

### 从 Docker 仓库中直接拉取镜像

请确保宿主机上已安装 Docker 且可访问外网，在命令行工具中运行下述语句从 Docker 仓库中拉取 Nginx 镜像：

```javascript
docker pull nginx

```

### 拷贝镜像包至宿主机中解压

1. 在可访问外网且已安装 Docker 的机器中运行下述语句，下载镜像包至本地：

   ```unknow
   docker save nginx:latest | gzip - >nginx.tar.gz

   ```
 2. 拷贝镜像包至宿主机中，运行下述语句加载镜像：

   ```javascript
   gunzip -c nginx.tar.gz | docker load

   ```

## 配置 conf 文件

在启动 Nginx 镜像前，需修改配置文件。ODC 的镜像包中已提供配置文件模板，可复制模板到本地并进行编辑。配置文件模板根据您是否已部署自签证书而略有不同，请按需复制对应的模板并进行修改。

### 配置不包含自签证书的 conf 文件

运行下述语句从镜像包中复制配置文件到宿主机再进行编辑，复制路径可自定义（其中 ~ 是配置文件在本地的路径）：

```javascript
docker cp -a <odc_image_name>:/opt/odc/conf/nginx.conf.template  ~/<conf_local_path>

```

配置文件模板如下所示，请关注文件中注释需修改的部分。

```javascript
# Nginx conf template for http deployment
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    #set 0 to disable request body size check, for support large size file upload
    client_max_body_size 0;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # for websocket configuration
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

    # load balancing configuration
    # notice under_score character are not allowed for upsteram name, 400 Bad Request happens if used
    # please use ip_hash strategy
    # one server line for each odc-server node
    upstream odcbackends {
      ip_hash;
      # PLEASE CHANGE to real odc-server address
      # 请修改为实际的 odc-server 地址（非必改内容）
      server xxx.x.x.x:8989;
      # add more servers here
    }

    #https server, proxy to odc-server 8989 port
    server {
        listen 80;
        # uncomment below if ipv6 enabled
        # 如启用 ipv6，请取消以下注释
        #listen [::]:80;

        # PLEASE CHANGE to your site domain
        # 请修改为实际的站点域名（非必改内容）
        server_name  odc.oceanbase.com;

        location / {
            proxy_pass http://odcbackends;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_read_timeout 1800;
            proxy_send_timeout 1800;
            proxy_connect_timeout 75;
            proxy_next_upstream off;
        }
    }

}

```

### 配置包含自签证书的 conf 文件

运行下述语句从镜像包中拷贝配置文件到宿主机再进行编辑，复制路径可自定义（其中 ～ 是配置文件在本地的路径）：

```javascript
docker cp -a <odc_image_name>:/opt/odc/conf/nginx.conf.https.template  ~/<conf_local_path>

```

```unknow
# Nginx conf template for https deployment
# For more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/

    # for websocket configuration
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

    # load balancing configuration
    # notice under_score character are not allowed for upsteram name, 400 Bad Request happens if used
    # please use ip_hash strategy
    # one server line for each odc-server node
    upstream odcbackends {
      ip_hash;
      # PLEASE CHANGE to real odc-server address
      # 请修改为实际的 odc-server 地址（非必改内容）
      server xxx.x.x.x:8989;
      #add more servers here
    }

    # redirect http to https
    server {
        listen 80 default_server;

        # uncomment below if ipv6 enabled
        # 如启用 ipv6，请取消以下注释
        #listen [::]:80 default_server;

        location / {
            return 301 https://$host$request_uri;
        }
    }

    # https server, proxy to odc-server 8989 port
    server {
        listen 443 ssl http2;
        # uncomment below if ipv6 enabled
        # 如启用 ipv6，请取消以下注释
        #listen [::]:443 ssl http2;

        # PLEASE CHANGE to your site domain
        # 请修改为实际的站点域名（非必改内容）
        server_name  odc.oceanbase.com;

        # you can use /opt/odc/bin/generate-odc-ssl-certificate.sh
        # to generate self certificated SSL certificates
        # 您可以使用 /opt/odc/bin/generate-odc-ssl-certificate.sh 生成自签证书

        # PLEASE CHANGE certificate file location if unmatched
        # 如不匹配，请修改证书文件路径
        ssl_certificate /etc/pki/nginx/odcserver.crt;
        ssl_certificate_key /etc/pki/nginx/odcserver.key;
        ssl_session_timeout 1d;
        ssl_session_cache shared:MozSSL:10m;  # about 40000 sessions
        ssl_session_tickets off;

        # intermediate configuration
        ssl_protocols TLSv1.2 TLSv1.3;
        ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
        ssl_prefer_server_ciphers off;

        # HSTS (ngx_http_headers_module is required) (63072000 seconds)
        add_header Strict-Transport-Security "max-age=63072000" always;

        location / {
            proxy_pass http://odcbackends;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
            proxy_read_timeout 1800;
            proxy_send_timeout 1800;
            proxy_connect_timeout 75;
            proxy_next_upstream off;
        }
    }

}

```

#### 说明

- 修改负载均衡配置，确保 proxy 超时配置时长充足，修改配置后需重启 nginx。
 - 建议 `proxy_connect_timeout` 参数不超过 75 秒，请参见 proxy_connect_timeout：http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_connect_timeout。
 - 设置 `proxy_next_upstream off` 旨在禁止 nginx 将请求转发至下一个 ODC 节点，导致用户需重新登录，且某些功能不可用，如异步任务结果集下载等与文件上传下载相关的功能。

## 启动镜像

在本地修改配置文件后，在命令行工具中运行下述语句以重启 Nginx 镜像（其中 ～ 是配置文件在本地的路径）：

```shell
docker run --network host --name nginx -v ～/<conf_local_path>:/etc/nginx/nginx.conf -v /etc/pki/nginx/:/etc/pki/nginx/ -d nginx

```

语句中的参数说明如下所示：

| 参数 | 说明 |
| --- | --- |
| --network host | 表示使用宿主机网络端口，无需配置端口映射。 如不希望直接使用宿主机端口，可使用 `-p` 参数配置端口映射。例如 `-p 8080:80` 表示宿主机的 8080 端口映射为 Docker 内的 80 端口，`-p 8443:443` 表示宿主机的 8443 端口映射为 Docker 内的 443 端口。 |
| --name nginx | 指定容器的名称为 nginx，方便后续管理，或可使用其它名称，如 odc-nginx。 |
| -v ~/<conf_local_path>:/etc/nginx/nginx.conf | 进行磁盘挂载，将宿主机内的本地文件映射到 Docker 内。 其中 `<conf_local_path>` 为配置 conf 文件时复制到宿主机的本地路径，然后将其映射至 Docker 内的 /etc/nginx/nginx.conf 文件中。 |
| -v /etc/pki/nginx/:/etc/pki/nginx/ | 将宿主机的 /etc/pki/nginx/ 路径映射到 Docker 内的 /etc/pki/nginx/ 路径。 |
| -d nginx | 表示后台运行 Docker。 |

 上一篇 下一篇 ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
