Web App 的自定义 URL 路径
自定义 URL 路径允许您修改 Web App 的基本 URL。在反向代理服务器(如 NGINX)后面部署应用程序时,该配置非常有用。通过设置自定义 URL 路径,您可以确保您的应用程序可通过组织基础设施所需的特定 URL 结构进行访问。
设置自定义 URL 路径
安装并配置 MATLAB® Web App Server™。
确保 MATLAB Web App Server 已安装,可在系统上运行。
验证是否可以使用默认 URL 访问服务器。
设置反向代理服务器
安装并配置反向代理服务器,如 NGINX。该服务器将处理传入的请求,并将其映射到正确的 URL 路径。
编辑反向代理服务器的配置文件。
打开 NGINX 配置文件,添加一个新的服务器模块来定义自定义 URL 路径。
为自定义路径指定服务器名称、监听端口和位置模块。
配置 URL 映射。
在位置模块中,使用
proxy_pass指令将请求转发至 MATLAB Web App Server。使用
proxy_redirect和rewrite指令可根据需要调整请求路径。
重新启动反向代理服务器。
编辑配置文件后,重启 NGINX 服务器以应用更改。
配置示例
访问 MATLAB Web App Server 的原始 URL 通常结构如下:
http://<webappserver_domain>:<webappserver_port>/webapps/home
自定义 URL 的结构如下
http://<proxy_domain>:<proxy_port>/<context>/<root>/webapps/home
假设您要为客户端 Acme 的名为 DataAnalytics 的工程设置自定义 URL 路径。访问 MATLAB Web App Server 主页的自定义 URL 将如下所示:
https://proxy.example.com:9993/acme/dataanalytics/appserver/webapps/home
例如,以下是配置 NGINX 的方法:
http {
# Maximum allowed request body size (for uploads, etc.)
client_max_body_size 100M;
# Map the client Upgrade header to an appropriate Connection value (needed for WebSocket support)
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
server_name proxy.example.com;
listen 0.0.0.0:9993 ssl default_server;
# TLS certificate and private key for this virtual host
ssl_certificate /path/to/your/certificate.crt;
ssl_certificate_key /path/to/your/private.key;
# Reverse proxy for MATLAB Web App Server, exposed under /acme/dataanalytics
location /acme/dataanalytics {
# Forward all requests to MATLAB Web App Server
proxy_pass https://webappserver.example.com:9988/;
# MATLAB Web App Server may redirect "/" to "/webapps/home" (using status 303).
# Without rewriting, the client would be redirected to /webapps/home at the proxy root.
# This ensures Location headers are rewritten to include the /acme/dataanalytics prefix.
proxy_redirect / /acme/dataanalytics/;
# Strip the /acme/dataanalytics/ prefix before forwarding to the upstream server.
# Example:
# Client: https://proxy.example.com:9993/acme/dataanalytics/foo
# Upstream: https://webappserver.example.com:9988/foo
rewrite ^/acme/dataanalytics/?(.*) /$1 break;
# WebSocket support
# Use HTTP/1.1 and forward Upgrade/Connection headers as sent by the client.
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
# NOTE:
# WebSocket connections require that both NGINX and MATLAB Web App Server
# use the same scheme (both HTTP or both HTTPS).
# If NGINX uses HTTPS but MATLAB Web App Server uses HTTP,
# the WebSocket handshake will fail.
}
}
}在此配置中:
NGINX 服务器通过
9993端口监听。自定义 URL 路径为
/acme/dataanalytics/。对该路径的请求将转发给在
http://webappserver.example.com:9988/上运行的 MATLAB Web App Server 。client_max_body_size属性被设置为100M。将此属性设置为 100 兆字节或更大,以避免在尝试从服务器主页上的 Manage Apps 链接上传 App 时出现错误。