Configure Separate Access Address for Files
In most browsers, the maximum number of concurrent requests to the same address is limited to 6. So if there are a large number of images in a worksheet view, a user accessing such a view with a click may result in a queue of browser requests. In this case, if the user switches to another page before the browser request has been fully loaded, he or she may experience a slowdown in browsing or even browser lag.
In response to the above, you first need to ensure that the file service instance resources and network bandwidth are sufficient. Second, you can follow this article to configure separate addresses for file requests to prevent file requests from blocking other interface requests.
Stand-alone Environment
If the separate address for file storage uses the default port 80/443 for http/https, you do not need to specify the default port 80/443 in its address when configuring the relevant environment variables.
Single System Access Address
In this example, the system access address is http://hap.domain.com
and the separate address for files is http://file.domain.com
.
Configuration Steps
-
Modify the configuration file
docker-compose.yaml
of the microservice.version: '3'
services:
app:
image: nocoly/hap-community:5.8.3
environment:
ENV_ADDRESS_MAIN: "http://hap.domain.com"
ENV_APP_VERSION: "5.8.3"
ENV_API_TOKEN: "******"
ENV_FILE_DOMAIN: "http://file.domain.com" # New variable, the specified separate address for files
ENV_FILE_ADDRESS_MAIN: "http://file.domain.com" # New variable, the specified separate address for files
ports:
- 8880:8880
- 9000:9000 # New port mapping, mapping port 9000 in the container to the host
volumes:
- ./volume/data/:/data/
- ../data:/data/hap/data
doc:
image: nocoly/hap-doc:1.2.0
environment:
ENV_FILE_INNER_URI: "app:9000" # Modified it to the address of file storage serviceConfiguration instructions for new variables:
ENV_FILE_DOMAIN
:Seperate address for files specified by file storage serviceENV_FILE_ADDRESS_MAIN
:Seperate address for files specified by microservice- If the seperate address for files uses the default port 80/443 of http/https, you do not need to specify its default port 80/443 when configuring the above two variables
Configuration instructions for new port mapping:
- 9000:9000
Map the port of file service in the container to the host to allow the nginx proxy to access the file service
Modification instructions for doc service variables:
ENV_FILE_INNER_URI
, Modify the default variable value toapp:9000
-
Restart microservice
-
Add nginx cross-domain proxy configuration for the seperate address for files, as shown below
upstream file {
server 192.168.0.10:9000; # The specified IP of the back-end microservice and the port of file storage service mapped to the microservice host
}
server {
listen 80;
server_name file.domain.com; # The specified seperate address for files
access_log /data/logs/weblogs/file.domain.com.log main; # Log path, customizable
error_log /data/logs/weblogs/file.domain.com.error.log; # Log path, customizable
location / {
if ($request_method = OPTIONS) {
return 204 "";
}
proxy_set_header HOST $http_host;
proxy_pass http://file;
proxy_hide_header Access-Control-Allow-Origin;
add_header Access-Control-Allow-Headers authorization,content-type;
add_header Access-Control-Allow-Origin "http://hap.domain.com"; # The specified system access address of HAP
}
} -
After the proxy configuration is complete, clear the browser cache. You can then use the developer tools in the browser to check whether file-related requests are taking the seperate address in Network.
Multiple System Access Addresses
When configuring seperate addresses for file services when there are multiple system access addresses, you need to configure a seperate address for each system access address.
In this example, the primary system access address is hap-external.domain.com
and the extended address is hap-internal.domain.com
.
The seperate addresses for files configured for the two access addresses are file-external.domain.com
and file-internal.domain.com
.
The correspondence between the system access address and the seperate access address for files is as follows:
Address Type | Primary Address | Extended Address |
---|---|---|
System Access Address | hap-external.domain.com | hap-internal.domain.com |
Seperate Address For Files | file-external.domain.com | file-internal.domain.com |
Configuration Steps
-
Modify the
docker-compose.yaml
file of the microservice, add the relevant configuration and restart the microservice.version: '3'
services:
app:
image: nocoly/hap-community:5.8.3
environment:
ENV_ADDRESS_MAIN: "http://hap-external.domain.com"
ENV_APP_VERSION: "5.8.3"
ENV_FILE_DOMAIN: "http://file-external.domain.com,http://file-internal.domain.com" # New variable, the specified multiple separate addresses for files
ENV_FILE_ADDRESS_MAIN: "http://file-external.domain.com" # New variable, the specified primary separate address for files
ports:
- 8880:8880
- 18880:18880
- 9000:9000 # New port mapping, mapping port 9000 in the container to the host
volumes:
- ./volume/data/:/data/
- ../data:/data/hap/data
doc:
image: nocoly/hap-doc:1.2.0
environment:
ENV_FILE_INNER_URI: "app:9000" # Modify it to the address of file storage serviceConfiguration instructions for new variables:
ENV_FILE_DOMAIN
Specify multiple separate addresses for files for file storage serviceENV_FILE_ADDRESS_MAIN
Specify the primary separate address for files for microservice- If the seperate address for files uses the default port 80/443 of http/https, you do not need to specify its default port 80/443 when configuring the above two variables
Configuration instructions for new port mapping:
- 9000:9000
Map the port of file service in the container to the host to allow the nginx proxy to access the file service
Modification instructions for doc service variables:
ENV_FILE_INNER_URI
, Modify the default variable value toapp:9000
-
Restart microservice
-
Add the nginx cross-domain proxy configuration for the primary seperate address for files, and the proxy configuration file can follow the configuration below:
upstream file {
server 192.168.0.10:9000; # The specified IP of the back-end microservice and the port of file storage service mapped to the microservice host
}
server {
listen 80;
server_name file-external.domain.com; # Specified main seperate address for files
access_log /data/logs/weblogs/file-external.domain.com.log main; # Log path, customizable
error_log /data/logs/weblogs/file-external.domain.com.error.log; # Log path, customizable
location / {
if ($request_method = OPTIONS) {
return 204 "";
}
proxy_set_header HOST $http_host;
proxy_pass http://file;
proxy_hide_header Access-Control-Allow-Origin;
add_header Access-Control-Allow-Headers authorization,content-type;
add_header Access-Control-Allow-Origin "http://hap-external.domain.com"; # Specified system main access address of HAP
}
} -
Add the nginx cross-domain proxy configuration for the extended seperate address for files, the proxy configuration file can follow the configuration below:
upstream file {
server 192.168.0.10:9000; # The specified IP of the back-end microservice and the port of file storage service mapped to the microservice host
}
server {
listen 80;
server_name file-internal.domain.com; # Specified extended seperate address for files
access_log /data/logs/weblogs/file-internal.domain.com.log main; # Log path, customizable
error_log /data/logs/weblogs/file-internal.domain.com.error.log; # Log path, customizable
location / {
if ($request_method = OPTIONS) {
return 204 "";
}
proxy_set_header HOST $http_host;
proxy_pass http://file;
proxy_hide_header Access-Control-Allow-Origin;
add_header Access-Control-Allow-Headers authorization,content-type;
add_header Access-Control-Allow-Origin "http://hap-internal.domain.com"; # System extended access address of HAP
}
} -
Modify the proxy for system extended address by adding the request header
pdfileaddr
field inlocation /
andlocation ~ /mds2
to specify the extended separate address for files, as follows:......
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_set_header pdaddr http://hap-internal.domain.com;
proxy_set_header pdfileaddr http://file-internal.domain.com; # New request header pdfileaddr, the specified extended separate address for files
proxy_pass http://hap-ext;
}
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-ext;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header pdaddr http://hap-internal.domain.com;
proxy_set_header pdfileaddr http://file-internal.domain.com; # New request header pdfileaddr, the specified extended separate address for files
}
...... -
After the proxy configuration is complete, clear the browser cache. You can then use developer tools in the browser to check if file-related requests in Network take the seperate address.
Cluster Environment
If the separate address for file storage uses the default port 80/443 for http/https, you do not need to specify the default port 80/443 in its address when configuring the relevant environment variables.
Single System Access Address
In this example, the system access address is http://hap.domain.com
and the separate address for files is http://file.domain.com
.
Configuration Steps
-
Modify the configuration file
docker-compose.yaml
of the microservice.- Kubernetes
- Docker Compose
-
Modify the
config.yaml
of the microservice and add the environment variableENV_FILE_ADDRESS_MAIN
as the specified separate address for files.ENV_FILE_ADDRESS_MAIN: "http://file.domain.com"
-
Modify the
service.yaml
of the microservice, and modify theENV_FILE_INNER_URI
of the doc service to the intranet address of file storage.env:
- name: ENV_FILE_INNER_URI
value: "192.168.0.10:9000" # Modify it to the intranet address of file storage -
Restart microservice
-
Modify the
docker-compose.yaml
of microservices and add the environment variableENV_FILE_ADDRESS_MAIN
to specify separate address for files.ENV_FILE_ADDRESS_MAIN: "http://file.domain.com"
-
Restart each microservice node
-
Modify configuration files for doc preview service, and modify the
ENV_FILE_INNER_URI
variable to the intranet address of file storage.ENV_FILE_INNER_URI: "192.168.0.10:9000" # Modify it to the intranet address of file storage
-
Restart doc preview services
-
Modify the configuration file
file.yaml
of the file storage service, add the relevant configuration, and restart the file storage service.-
Modify the configuration file
file.yaml
of the file storage service and add a new environment variableENV_FILE_DOMAIN
to specify a separate address for file storage service.ENV_FILE_DOMAIN: "http://file.domain.com"
-
Restart the file storage service.
-
-
Add nginx cross-domain proxy configuration for the seperate address for files, as shown below:
upstream file {
server 192.168.0.10:9000; # Specified IP and port of file storage service
}
server {
listen 80;
server_name file.domain.com; # The specified separate address for files
access_log /data/logs/weblogs/file.domain.com.log main; # Log path, customizable
error_log /data/logs/weblogs/file.domain.com.error.log; # Log path, customizable
location / {
if ($request_method = OPTIONS) {
return 204 "";
}
proxy_set_header HOST $http_host;
proxy_pass http://file;
proxy_hide_header Access-Control-Allow-Origin;
add_header Access-Control-Allow-Headers authorization,content-type;
add_header Access-Control-Allow-Origin "http://hap.domain.com"; # Specified system access address of HAP
}
} -
After the proxy configuration is complete, clear the browser cache. You can then use developer tools in the browser to check if file-related requests in Network take the seperate address.
Multiple System Access Addresses
When configuring seperate addresses for file services when there are multiple system access addresses, you need to configure a seperate address for each system access address.
In this example, the primary system access address is hap-external.domain.com
and the extended address is hap-internal.domain.com
.
The seperate addresses for files configured for the two access addresses are file-external.domain.com
and file-internal.domain.com
.
The correspondence between the system access address and the seperate access address for files is as follows:
Address Type | Primary Address | Extended Address |
---|---|---|
System Access Address | hap-external.domain.com | hap-internal.domain.com |
Seperate Address For Files | file-external.domain.com | file-internal.domain.com |
Configuration Steps
-
Modify the yaml file of the microservice.
- Kubernetes
- Docker Compose
-
Modify the configuration file
config.yaml
for microservice and add a new environment variableENV_FILE_ADDRESS_MAIN
to specify the primary separate address for files for microservice.ENV_FILE_ADDRESS_MAIN: "http://file-external.domain.com"
-
Modify the configuration file
service.yaml
for the microservice and modify theENV_FILE_INNER_URI
variable for the doc service to the intranet address of file storage.env:
- name: ENV_FILE_INNER_URI
value: "192.168.0.10:9000" # Modify it to the intranet address for file storage -
Restart microservice.
-
Modify the configuration file
docker-compose.yaml
for each microservice and add a new environment variableENV_FILE_ADDRESS_MAIN
to specify the primary separate address for files for the microservices.ENV_FILE_ADDRESS_MAIN: "http://file-external.domain.com"
-
Restart each microservice node.
-
Modify the configuration files for the doc preview service and modify the
ENV_FILE_INNER_URI
variable to the intranet address of file storage.ENV_FILE_INNER_URI: "192.168.0.10:9000" # Modify it to the intranet address of file storage
-
Restart doc preview services.
-
Modify the configuration file
file.yaml
of the file storage service, add the relevant configuration and restart the file storage service.-
Modify the configuration file
file.yaml
for the file storage service and add the environment variableENV_FILE_DOMAIN
to specify multiple separate addresses for the file storage service.ENV_FILE_DOMAIN: "http://file-external.domain.com,http://file-internal.domain.com"
-
Restart file storage service.
-
-
Add the nginx cross-domain proxy configuration for the primary seperate address for files, and the proxy configuration file can follow the configuration below:
upstream file {
server 192.168.0.10:9000; # Specified IP and port of file storage service
}
server {
listen 80;
server_name file-external.domain.com; # Specified primary separate address for files
access_log /data/logs/weblogs/file-external.domain.com.log main; # Log path, customizable
error_log /data/logs/weblogs/file-external.domain.com.error.log; # Log path, customizable
location / {
if ($request_method = OPTIONS) {
return 204 "";
}
proxy_set_header HOST $http_host;
proxy_pass http://file;
proxy_hide_header Access-Control-Allow-Origin;
add_header Access-Control-Allow-Headers authorization,content-type;
add_header Access-Control-Allow-Origin "http://hap-external.domain.com"; # Specified system main access address of HAP
}
} -
Add the nginx cross-domain proxy configuration for the extended seperate address for files, the proxy configuration file can follow the configuration below:
upstream file {
server 192.168.0.10:9000; # Specified IP and port of file storage service
}
server {
listen 80;
server_name file-internal.domain.com; # Specified extended separate address for files
access_log /data/logs/weblogs/file-internal.domain.com.log main; # Log path, customizable
error_log /data/logs/weblogs/file-internal.domain.com.error.log; # Log path, customizable
location / {
if ($request_method = OPTIONS) {
return 204 "";
}
proxy_set_header HOST $http_host;
proxy_pass http://file;
proxy_hide_header Access-Control-Allow-Origin;
add_header Access-Control-Allow-Headers authorization,content-type;
add_header Access-Control-Allow-Origin "http://hap-internal.domain.com"; # System extended access address of HAP
}
} -
Modify the proxy for system extended address by adding the request header
pdfileaddr
field inlocation /
andlocation ~ /mds2
to specify the extended separate address for files, as follows:......
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_set_header pdaddr http://hap-internal.domain.com;
proxy_set_header pdfileaddr http://file-internal.domain.com; # New request header pdfileaddr, the specified extended separate address for files
proxy_pass http://hap-ext;
}
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-ext;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection upgrade;
proxy_set_header pdaddr http://hap-internal.domain.com;
proxy_set_header pdfileaddr http://file-internal.domain.com; # New request header pdfileaddr, the specified extended separate address for files
}
...... -
After the proxy configuration is complete, clear the browser cache. You can then use developer tools in the browser to check if file-related requests in Network take the seperate address.