Web Service Integration Guide for RobustOS Pro

Web Service Integration Guide for RobustOS Pro

1. Core Conventions

Before starting, please follow these conventions to avoid affecting system stability.

1.1 Files and Directories

PathPurposeAction
/etc/nginx/sites-available/Configuration files for standalone port servicesCreate new files here
/etc/nginx/server_common_conf/Configuration files for location proxiesCreate new files here
/etc/nginx/nginx.conf.rospSystem Nginx configuration templateDO NOT modify
/etc/nginx/sites-available/rosp_webSystem main Web service configurationDO NOT modify

1.2 Port Usage

Port RangeStatusDescription
80, 443System reservedWeb management interface, do not use directly
1880, 8080, 8090Service reservedNode-RED, ChirpStack, etc.
8081-8089RecommendedCustom HTTP services
9000-9999RecommendedCustom TCP/UDP services

All operations require root privileges.

If your application needs to use the default Web service ports (80/443), you must change the system Web service ports to other ports. Run the following commands to modify the default Web management interface ports:

sudo uci set web_server.http_port 8080
sudo uci set web_server.https_port 8443

sudo uci commit

2. Comparison of Two Methods

Choose the most suitable method based on your requirements.

FeatureMethod 1: Standalone PortMethod 2: Location Proxy
Access Methodhttp://device-IP:port/https://device-IP/path/
Use CasesIndependent Web apps, monitoring dashboards, documentationAPI services, backends requiring unified entry point
SSLNot supportedAutomatically enabled (recommended)
AdvantagesIsolated configuration, no mutual impactUnified access point, more secure
DisadvantagesNeed to manage additional ports, no HTTPSNeed to plan URL paths to avoid conflicts

Tip: HTTP (80) access is automatically redirected to HTTPS (443) by default, so Location Proxy only works under HTTPS.

3. Deployment Steps

3.1 Method 1: Adding a Standalone Port Service

Example: deploying a static website on port 8888.

1. Create Configuration File

# Write configuration to /etc/nginx/sites-available/my_static_site
sudo tee /etc/nginx/sites-available/my_static_site > /dev/null <<'EOF'
server {
    listen 8888;
    server_name _;

    root /var/www/my_static_site;
    index index.html;

    # Simplified logging and security headers
    access_log /var/log/nginx/my_static_site.log;
    error_log /var/log/nginx/my_static_site.error.log;
    add_header X-Frame-Options "SAMEORIGIN";

    location / {
        try_files $uri $uri/ =404;
    }
}
EOF

2. Create Web Files

sudo mkdir -p /var/www/my_static_site
echo "<h1>Hello from Port 8888</h1>" | sudo tee /var/www/my_static_site/index.html

3. Enable Service

# Create symlink to enable
sudo ln -s /etc/nginx/sites-available/my_static_site /etc/nginx/sites-enabled/

# Test configuration and reload
sudo nginx -t && sudo systemctl reload nginx

Access: http://:8888

3.2 Method 2: Adding a Location Proxy

Proxy all requests to https://device-IP/myapp/ to a local service running on port 5000.

1. Create Proxy Configuration

# Write configuration to /etc/nginx/server_common_conf/myapp_proxy.conf
sudo tee /etc/nginx/server_common_conf/myapp_proxy.conf > /dev/null <<'EOF'
location /myapp/ {
    proxy_pass http://127.0.0.1:5000/; # Note the trailing slash
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}
EOF

2. Reload Nginx

sudo nginx -t && sudo systemctl reload nginx

Access: https:///myapp/ (Note: use HTTPS)

4. Diagnostics and Recovery

4.1 Quick Diagnostic Commands

CommandPurpose
sudo nginx -tPreferred, check all configuration file syntax
sudo systemctl status nginxView Nginx service running status
ss -tlnpgrep nginx
tail -50 /var/log/nginx/error.logView recent error logs
tail -f /var/log/nginx_config_fixes.logView system auto-fix logs

4.2 Common Issues

IssuePossible Causes & Solutions
Configuration not taking effectForgot to reload: sudo systemctl reload nginx
502 Bad GatewayBackend service not running or incorrect port. Check backend service.
Location proxy 404Path configuration error or using HTTP. Must use HTTPS.
Port inaccessiblePort conflict or not listening. Check with ss -tlnp.
Configuration rolled backSevere syntax error. Check /var/log/nginx_config_fixes.log.

4.3 Quick Recovery

If configuration causes Nginx to fail to start, follow these steps to restore to system default configuration.

sudo systemctl stop nginx
# Remove custom symlinks and proxy configurations
sudo rm -f /etc/nginx/sites-enabled/my_static_site
sudo rm -f /etc/nginx/server_common_conf/myapp_proxy.conf
# Re-link default service
sudo ln -s /etc/nginx/sites-available/rosp_web /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl start nginx

5. Common Scenario Configurations

5.1 WebSocket Proxy

# ... above or below proxy_pass and other directives
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";

5.2 Proxy to Docker Container

Proxy to Grafana container (port 3000) and map to /monitoring/ path.

location /monitoring/ {
    # rewrite directive removes /monitoring/ prefix from URL
    rewrite ^/monitoring/(.*) /$1 break;
    proxy_pass http://127.0.0.1:3000;

    # ... other proxy_set_header directives ...
}

Note: Some applications (like Grafana) require their own root_url configuration to support subpath access.

5.3 Adding HTTP Basic Authentication

Protect path /admin/, requiring username and password for access.

1. Install Tools and Create Password

sudo apt-get update && sudo apt-get install -y apache2-utils
sudo htpasswd -c /etc/nginx/auth.htpasswd admin
# Enter password when prompted

2. Add Authentication in Location Configuration

location /admin/ {
    auth_basic "Restricted Area";
    auth_basic_user_file /etc/nginx/auth.htpasswd;

    # ... proxy_pass and other directives ...
}

Appendix

  • Nginx Official Documentationhttps://nginx.org/en/docs/

  • Configuration File Naming: Recommend using descriptive names, such as monitoring_dashboard, rather than app1.

  • File Permissions: Configuration files (.conf) recommended 644, Web directories recommended 755, Web files recommended 644.

    • Related Articles

    • NetworkManager Integration Guide

      1. Overview This document provides guidance for third-party application developers working on network-related development on RobustOS Pro devices. RobustOS Pro uses NetworkManager (NM) as its core network management service and provides two primary ...
    • RobustOS Pro Third-Party Application Development Guide

      1. Quick Overview What is RobustOS Pro? RobustOS Pro is an embedded Linux distribution based on Debian 11 (bullseye), designed specifically to meet the demanding requirements of industrial IoT gateways, providing a high degree of customization and ...
    • RobustOS Pro SDK - Quick Start Guide

      Prerequisites Before you begin, ensure you have: Hardware: One of the supported RobustOS Pro devices (EG5100, LG5100, R1520LG, EV8100, EG5101, EG5200, EG5120, or EG3110) Network Access: SSH access to your device User Account: A sudo user account on ...
    • RobustOS Pro Application Development Getting Started

      Preface Welcome to RobustOS Pro! This guide provides a step-by-step roadmap for understanding, developing, and deploying applications on the platform. This document is only applicable to RobustOS Pro 2.4.x firmware versions. System Architecture ...
    • How to Integrate WhatsApp Alarm Systems on RobustOS Pro Gateways

      In today's interconnected industrial environments, timely notifications about critical events can prevent costly downtime and rapid response to potential issues. As a leading provider of industrial IoT solutions, Robustel continues to innovate with ...