HTTP Proxying to Jobson

The main jobson java server hosts a standard JSON API that is accessed via HTTP. The default port for the JSON API is 8080, which can be changed in the server configuration.

In standard production deployments, a jobson server is typically hosted behind a a reverse proxy such as nginx, which adds HTTP encryption, load balancing, or path matching. Path matching is how jobson-ui is integrated with jobson: jobson-ui can be made to prefix all API call paths to jobson with (e.g.) /api, which the reverse proxy can then use to forward traffic to a jobson server.

The server also hosts a websocket server, which is used to stream stdio updates directly to clients as they happen (e.g. jobson-ui uses this to update the console log dynamically). The websocket API is not strictly required to use jobson - jobson-ui should function fine without websockets, but won’t dynamically update.

Nginx

  • Create an nginx config file for the site at /etc/nginx/sites-available/jobson-ui:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
server {
	listen 8090;
	listen [::]:8090;

	root /var/www/jobson-ui;

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ =404;
	}

	location /api {
		# Any requests beginning with /api should be forwarded
		# to Jobson
		proxy_pass http://localhost:8080;

		# The Jobson server itself doesn't take an /api prefix
		# (it's just used for routing), so drop it.
		rewrite ^/api/(.*) /$1 break;

		# Enable websockets, which are used for dynamic updates
		# (Jobson UI doesn't *require* them though).
		proxy_http_version 1.1;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header Connection "upgrade";
		proxy_read_timeout 86400;
	}
}
  • Enable the site configuration:

cd /etc/nginx/sites-enabled
ln -s ../sites-available/jobson-ui jobson-ui
  • Reload nginx:

nginx -s reload

Apache

Thanks to Odgen Brash for testing + documenting this.

  • Install apache2 as normal

  • Update your virtual host configuration to proxy API requests to a running jobson server:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# apache virtual host config (e.g. at
# /etc/apache2/sites-enabled/000-default.conf on Ubuntu installs)

<VirtualHost *:80>
        # (other apache config options)
        # .
        # .
        # .
        # (insert below lines, assuming `jobson` is running locally on port 8080)
        # these options depend on `mod_rewrite`, `mod_proxy`, and
        # `mod_proxy_http`

        # proxy all requests beginning with /api/ to jobson server at
        # localhost:8080
        
        RewriteEngine On
        RewriteRule "^/api/(.*)" "http://localhost:8080/$1" [P]
        ProxyPassReverse "/api/" "http://localhost:8080/"
</VirtualHost>
  • Enable required mods:

a2enmod rewrite proxy proxy_http
  • Restart apache2:

apache2ctl restart