Skip to main content

Multiple Access Address Configuration

Dual Address

By default, an access exception occurs if the second access address of the system is directly proxy forwarded to the current original system address.

Due to the characteristics of HAP service, if you need to configure the second access address of the system, you need to forward the request to port 18880 in the container and specify the second access address in the configuration file before you can use the system through the second access address normally.

Configuration

  1. Modify the file docker-compose.yaml.

    Add a new variable under environment to specify the second access address.

    ENV_EXT_MINGDAO_PROTO: "https"
    ENV_EXT_MINGDAO_HOST: "hap2.domain.com"
    ENV_EXT_MINGDAO_PORT: "443"

    Add port mapping under ports to map port 18880 out of the container.

    - 18880:18880
    docker-compose.yaml Example of Configuration File
    version: '3'

    services:
    app:
    image: nocoly/hap-community:5.8.0
    environment:
    ENV_ADDRESS_MAIN: "http://hap1.domain.com:80"
    ENV_APP_VERSION: "5.8.0"
    ENV_API_TOKEN: "******"
    ENV_EXT_MINGDAO_PROTO: "https" # Add
    ENV_EXT_MINGDAO_HOST: "hap2.domain.com" # Add
    ENV_EXT_MINGDAO_PORT: "443" # Add
    ports:
    - 8880:8880
    - 18880:18880 # Add
    volumes:
    - ./volume/data/:/data/
    - ../data:/data/hap/data
    • Note that there are four additions in docker-compose.yaml.
  2. Restart the HAP service in the directory of Install Manager to take effect.

    bash ./service.sh restartall
  3. Forward the second access address request to port 18880 of the server.

Multiple Address

If the system is to be configured with three, four, or more access addresses, the dual-address configuration method described above is not applicable, and you can refer to the following method of adding the pdaddr header to realize multi-address access to the system through the nginx proxy (Microservice Version: v3.5.0+).

Note: When configuring multiple addresses in this way, the configuration file dockerc-compose.yaml cannot contain ENV_EXT_MINGDAO_PROTO, ENV_EXT_MINGDAO_HOST or ENV_EXT_MINGDAO_PORT.

Configuration

  1. Add port mapping under the app service ports in docker-compose.yaml to map the 18880 port in the container.

    - 18880:18880
  2. Add a variable in the app service environment with the value of your extended access address. Separate multiple values with commas

    ENV_ADDRESS_ALLOWLIST: "https://hap2.domain.com"
  3. Restart the HAP service in the directory of Install Manager to take effect.

    bash ./service.sh restartall
  4. Configure the file for nginx. Reverse proxy the new access address to port 18880 of HAP microservice.

    The reverse proxy configuration file for nginx is as follows:

  5. Add proxy_set_header pdaddr under localtion in the configuration file of nginx to specify the system access address.

    Example:

    location / {
    set $real_ip '';
    if ($http_x_real_ip) {
    set $real_ip $http_x_real_ip;
    }
    if ($http_x_real_ip = '') {
    set $real_ip $remote_addr;
    }
    proxy_set_header X-Real-IP $real_ip;
    proxy_set_header Host $http_host;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_pass http://hap;
    proxy_set_header pdaddr https://hap2.domain.com; # New, please note to modify to your actual extended access address
    }

    # IM Requirements
    location ~ /mds2 {
    proxy_set_header Host $http_host;
    proxy_hide_header X-Powered-By;
    proxy_set_header X-NginX-Proxy true;
    proxy_pass http://hap;
    proxy_redirect off;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection upgrade;
    proxy_set_header pdaddr https://hap2.domain.com; # New, please note to modify to your actual extended access address
    }
  6. After reloading nginx, you can use HAP system with a new access address.