Flink Web Proxy Configuration
Flink Web is an administration interface. Access it only from a controlled network, enable authentication, and avoid exposing it directly to the public internet.
Configuration Steps
- External Nginx
- Single-node Docker Compose
- Kubernetes Cluster
1. Prepare the Configuration
If you are deploying Nginx outside the container, first refer to Nginx Deployment to complete the installation and basic configuration. Then refer to HTTP Proxy Configuration or HTTPS Proxy Configuration to configure the HAP proxy.
The following examples use:
- Nginx configuration file:
/usr/local/nginx/conf/conf.d/hap.conf - Flink service address:
http://192.168.10.30:8081
Make sure the host running external Nginx can access http://192.168.10.30:8081. If the address is unreachable, the Flink Web proxy will not work.
2. Back Up the Configuration File
cp -p /usr/local/nginx/conf/conf.d/hap.conf /usr/local/nginx/conf/conf.d/hap.conf.bak.$(date +%Y%m%d%H%M%S)
3. Add the Flink Proxy Configuration
Edit the HAP proxy configuration file:
vi /usr/local/nginx/conf/conf.d/hap.conf
Add the following location block to the server block for the HAP access address. Do not add it to the upstream hap block:
location /privatedeploy/mdy/monitor/flink/ {
auth_basic "Flink Web";
auth_basic_user_file /usr/local/nginx/conf/conf.d/.flink_passwd;
rewrite ^/privatedeploy/mdy/monitor/flink$ / break;
rewrite ^/privatedeploy/mdy/monitor/flink/(.*)$ /$1 break;
proxy_pass http://192.168.10.30:8081; # Replace with the actual Flink Web service address
return 200 "ok";
}
- Add this
locationblock to theserverblock for the HAP access address. Do not place it inupstream hap. - Set
proxy_passto the actual Flink Web service address. - For an HTTPS proxy, add the configuration to the
serverblock listening on443 ssl. For an HTTP proxy, add it to theserverblock listening on80.
Combined Example with the HAP Proxy Configuration
Use the following example as a reference for /usr/local/nginx/conf/conf.d/hap.conf. Modify the HAP backend address, certificate paths, and Flink service address according to your environment.
- HTTP
- HTTPS
upstream hap {
server 服务器IP:8880; # Change to the HAP system's internal IP and port
}
server {
listen 80;
server_name _;
access_log /data/logs/weblogs/hap.log main;
error_log /data/logs/weblogs/hap.error.log;
underscores_in_headers on;
client_max_body_size 2048m;
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;
}
# Required by IM
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;
}
# SSE streaming responses and long-lived connections
location ~ ^/(agent|api/workflow/api/sse/chat) {
set $md_real_ip '';
if ($http_x_real_ip) {
set $md_real_ip $http_x_real_ip;
}
if ($http_x_real_ip = '') {
set $md_real_ip $remote_addr;
}
proxy_buffering off;
proxy_read_timeout 30m;
proxy_send_timeout 30m;
client_max_body_size 16m;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $md_real_ip;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-HTTP-Method-Override "";
proxy_pass http://hap;
proxy_redirect default;
}
location /privatedeploy/mdy/monitor/flink/ {
auth_basic "Flink Web";
auth_basic_user_file /usr/local/nginx/conf/conf.d/.flink_passwd;
rewrite ^/privatedeploy/mdy/monitor/flink$ / break;
rewrite ^/privatedeploy/mdy/monitor/flink/(.*)$ /$1 break;
proxy_pass http://192.168.10.30:8081; # Replace with the actual Flink Web service address
return 200 "ok";
}
}
upstream hap {
server 服务器IP:8880; # Change to the HAP system's internal IP and port
}
server {
listen 80;
server_name _;
rewrite ^(.*)$ https://$host$1 permanent;
}
server {
listen 443 ssl;
server_name _;
access_log /data/logs/weblogs/hap.log main;
error_log /data/logs/weblogs/hap.error.log;
ssl_certificate /etc/cert/fullchain.pem; # Change to the SSL certificate path
ssl_certificate_key /etc/cert/privkey.pem; # Change to the SSL private key path
underscores_in_headers on;
client_max_body_size 2048m;
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;
}
# Required by IM
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;
}
# SSE streaming responses and long-lived connections
location ~ ^/(agent|api/workflow/api/sse/chat) {
set $md_real_ip '';
if ($http_x_real_ip) {
set $md_real_ip $http_x_real_ip;
}
if ($http_x_real_ip = '') {
set $md_real_ip $remote_addr;
}
proxy_buffering off;
proxy_read_timeout 30m;
proxy_send_timeout 30m;
client_max_body_size 16m;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $md_real_ip;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-HTTP-Method-Override "";
proxy_pass http://hap;
proxy_redirect default;
}
location /privatedeploy/mdy/monitor/flink/ {
auth_basic "Flink Web";
auth_basic_user_file /usr/local/nginx/conf/conf.d/.flink_passwd;
rewrite ^/privatedeploy/mdy/monitor/flink$ / break;
rewrite ^/privatedeploy/mdy/monitor/flink/(.*)$ /$1 break;
proxy_pass http://192.168.10.30:8081; # Replace with the actual Flink Web service address
return 200 "ok";
}
}
4. Create the Login Account
The login username is hap. YourStrongPassword123 in the command is only an example. Replace it with the actual password before running the command. The password can contain only letters and digits. Use a strong password:
printf "hap:$(openssl passwd -apr1 'YourStrongPassword123')\n" > /usr/local/nginx/conf/conf.d/.flink_passwd
5. Check and Reload Nginx
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
This method modifies the Nginx configuration in the running container. The changes will be lost after the container restarts and must be configured again.
1. Confirm the Flink Service Address
Choose either of the following methods to obtain the value of ENV_FLINK_URL:
- View Container Environment Variables
- View docker-compose.yaml
Run the following command on the HAP deployment server:
docker exec -it $(docker ps -a | grep -E 'mingdaoyun-community|mingdaoyun-hap' | awk '{print $1}') bash
Run the following command in the HAP container:
export | grep -i ENV_FLINK
The default configuration file is /data/mingdao/script/docker-compose.yaml. Run the following command on the HAP deployment server:
grep -n -i 'ENV_FLINK_URL' /data/mingdao/script/docker-compose.yaml
Copy only the address value corresponding to ENV_FLINK_URL, not the variable name or the entire line. Use it to replace the proxy_pass address in the Nginx configuration.
2. Back Up the Nginx Configuration in the Container
cp -p /usr/local/nginx/conf/conf.d/private.conf /usr/local/nginx/conf/conf.d/private.conf.bak.$(date +%Y%m%d%H%M%S)
3. Modify the Nginx Configuration in the Container
vi /usr/local/nginx/conf/conf.d/private.conf
Find the server { ... } block for the access address and paste the following content before the last }.
Tip: This block is usually at the end of the file. Add a blank line above the final }, then paste the following configuration.
location /privatedeploy/mdy/monitor/flink/ {
auth_basic "Flink Web";
auth_basic_user_file /usr/local/nginx/conf/conf.d/.flink_passwd;
rewrite ^/privatedeploy/mdy/monitor/flink$ / break;
rewrite ^/privatedeploy/mdy/monitor/flink/(.*)$ /$1 break;
proxy_pass http://flink:8081; # Replace with the actual ENV_FLINK_URL value
return 200 "ok";
}
4. Create the Login Account
The login username is hap. YourStrongPassword123 in the command is only an example password. Replace it with the actual password before running the command. The password can contain only letters and digits. Do not use the example password directly.
printf "hap:$(openssl passwd -apr1 'YourStrongPassword123')\n" > /usr/local/nginx/conf/conf.d/.flink_passwd
5. Check and Reload Nginx
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
6. Exit the Container
exit
This method modifies the Nginx configuration in the running container. The changes will be lost after the container restarts and must be configured again.
1. Confirm the Flink Service Address
Choose either of the following methods to obtain the value of ENV_FLINK_URL:
- View config Pod Environment Variables
- View config.yaml
Run the following command on the control node. Replace default with the actual namespace:
kubectl -n default exec -it $(kubectl -n default get pod | grep config | awk '{print $1}') -- bash
Run the following command in the config Pod:
export | grep -i ENV_FLINK
After checking the value, exit the config Pod:
exit
The default configuration file is /data/mingdao/script/kubernetes/config.yaml. Run the following command on the control node:
grep -n -i 'ENV_FLINK_URL' /data/mingdao/script/kubernetes/config.yaml
Copy only the address value corresponding to ENV_FLINK_URL, not the variable name or the entire line. Use it to replace the proxy_pass address in the Nginx configuration.
2. Enter a www Pod and Back Up the Nginx Configuration
First, list all www Pod names:
kubectl -n default get pod | grep www
If there are multiple www Pods, complete steps 2–6 for each Pod. The new Nginx configuration, username, and password must be the same in all Pods.
Replace <www-pod> with each actual Pod name and enter the Pods one by one:
kubectl -n default exec -it <www-pod> -- bash
cp -p /usr/local/nginx/conf/conf.d/private.conf /usr/local/nginx/conf/conf.d/private.conf.bak.$(date +%Y%m%d%H%M%S)
3. Modify the Nginx Configuration in the www Pod
Edit the Nginx configuration:
vi /usr/local/nginx/conf/conf.d/private.conf
Find the server { ... } block for the access address and paste the following content before the last }.
Tip: This block is usually at the end of the file. Add a blank line above the final }, then paste the following configuration.
location /privatedeploy/mdy/monitor/flink/ {
auth_basic "Flink Web";
auth_basic_user_file /usr/local/nginx/conf/conf.d/.flink_passwd;
rewrite ^/privatedeploy/mdy/monitor/flink$ / break;
rewrite ^/privatedeploy/mdy/monitor/flink/(.*)$ /$1 break;
proxy_pass http://flink:8081; # Replace with the actual ENV_FLINK_URL value
return 200 "ok";
}
4. Create the Login Account
The login username is hap. YourStrongPassword123 in the command is only an example password. Replace it with the actual password before running the command. The password can contain only letters and digits. Do not use the example password directly.
printf "hap:$(openssl passwd -apr1 'YourStrongPassword123')\n" > /usr/local/nginx/conf/conf.d/.flink_passwd
5. Check and Reload Nginx
/usr/local/nginx/sbin/nginx -t
/usr/local/nginx/sbin/nginx -s reload
6. Exit the Container
exit
Access URL
After completing the configuration, open the following address in a browser and sign in with the configured credentials:
<HAP access address>/privatedeploy/mdy/monitor/flink/
Replace <HAP access address> with the actual HAP access address.
The login username is hap, and the password is the one configured during setup.