StreamServer推理服务并不是一个完备的系统,需要通过组件集成方式与用户其他系统配合才能形成一个完整的推理服务系统,建议用户在StreamServer服务前部署Nginx,建议不要使用root用户启动Nginx。同时建议开启Nginx的日志功能,以此记录正常的访问日志和错误请求日志。同时为了防止日志文件过大,需要定时对日志文件进行切割压缩。如果切割压缩后文件仍然过大,可以将割接和压缩过的日志文件转储到其它地方。
apt install nginx
worker_processes 1; worker_cpu_affinity 0001; worker_rlimit_nofile 4096; events { worker_connections 4096; } http { port_in_redirect off; server_tokens off; autoindex off; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" "$request_time"'; access_log /var/log/nginx/access.log main; error_log /var/log/nginx/error.log info; limit_req_zone global zone=req_zone:100m rate=20r/s; limit_conn_zone global zone=north_conn_zone:100m; server { listen 127.0.0.1:8081 ssl; # 反向代理的服务端ip及端口,必须配置为服务器ip,不建议设置为空 server_name localhost; add_header Referrer-Policy "no-referrer"; add_header X-XSS-Protection "1; mode=block"; add_header X-Frame-Options DENY; add_header X-Content-Type-Options nosniff; add_header Strict-Transport-Security " max-age=31536000; includeSubDomains "; add_header Content-Security-Policy "default-src 'self'"; add_header Cache-control "no-cache, no-store, must-revalidate"; add_header Pragma no-cache; add_header Expires 0; ssl_session_tickets off; ssl_certificate ${path_of_server_crt_1}; # 服务端证书路径(权限400) ssl_certificate_key ${path_of_server_key_1}; # 服务端私钥路径,私钥不能明文配置(权限400) ssl_client_certificate ${path_of_ca_crt_1}; # 根ca证书路径(权限400) send_timeout 60; limit_req zone=req_zone burst=20 nodelay; limit_conn north_conn_zone 20; keepalive_timeout 60; proxy_read_timeout 900; proxy_connect_timeout 60; proxy_send_timeout 60; client_header_timeout 60; client_body_timeout 10; client_header_buffer_size 2k; large_client_header_buffers 4 8k; client_body_buffer_size 16K; client_max_body_size 20m; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS !RC4"; ssl_verify_client on; ssl_verify_depth 9; ssl_session_timeout 10s; ssl_session_cache shared:SSL:10m; location / { limit_except OPTIONS HEAD { deny all; } proxy_hide_header X-Powered-By; } location /v2 { proxy_pass https://127.0.0.1:8080; # 需要设置为StreamServer配置文件配置的ip及端口 allow 127.0.0.1; #需要设置允许访问的远端ip deny all; proxy_ssl_certificate ${path_of_server_crt_2}; # 服务端证书路径,建议配置通过certImport.sh脚本导入到${MX_SDK_HOME}/samples/mxVision/streamserver/keys目录下的server.crt (权限400) proxy_ssl_certificate_key ${path_of_server_key_2}; # 服务端私钥路径,私钥不能明文配置,建议配置通过certImport.sh脚本导入到${MX_SDK_HOME}/samples/mxVision/streamserver/keys目录下的server.key (权限400) proxy_ssl_trusted_certificate ${path_of_ca_crt_2}; # 根ca证书路径,建议配置通过certImport.sh脚本导入到${MX_SDK_HOME}/samples/mxVision/streamserver/keys目录下的ca.crt (权限400) proxy_ssl_session_reuse on; proxy_ssl_protocols TLSv1.2 TLSv1.3; proxy_ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384"; } } }
${path_of_nginx_bin} -c ${path_of_nginx_config_file} # nginx配置文件