Skip to content

Instantly share code, notes, and snippets.

@alexandrule
Forked from rennex/foo.service
Created July 18, 2023 11:34
Show Gist options
  • Save alexandrule/a8b3de3e6ad79b2428c2cf5ebe7ef1d5 to your computer and use it in GitHub Desktop.
Save alexandrule/a8b3de3e6ad79b2428c2cf5ebe7ef1d5 to your computer and use it in GitHub Desktop.
Example of a systemd service file to start a Sinatra app.
# /etc/systemd/system/foo.service
[Unit]
Description=Foo service
Wants=nginx.service
Requires=postgresql.service
After=postgresql.service
[Service]
Type=simple
User=foo
Group=foo
ExecStart=/srv/foo/app/serve
Restart=always
TimeoutSec=10
[Install]
WantedBy=multi-user.target
# /etc/nginx/sites-enabled/foo
# example nginx config, which proxies /foo to this app
server {
# ...basic stuff omitted...
location / {
try_files $uri $uri/ =404;
}
location /foo {
# this nginxroot directory has "foo" symlinked to /srv/foo/app/public
# to avoid having to rewrite that prefix out here :)
root /srv/foo/nginxroot;
try_files $uri @foosinatra;
}
location @foosinatra {
include /etc/nginx/sinatra_params;
proxy_pass http://localhost:1234;
}
}
#!/bin/sh
cd $(dirname $(readlink -f "$0"))
rackup --env production -o 127.0.0.1 -p 1234 >>log/production.log 2>&1
# /etc/nginx/sinatra_params
# extra headers that seem to be needed for Sinatra apps, especially when nginx uses https
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Host $http_host;
proxy_set_header Connection "";
proxy_http_version 1.1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment