Skip to content

Instantly share code, notes, and snippets.

@benubois benubois/setup.sh
Created Apr 17, 2018

Embed
What would you like to do?
ruby cgi server setup
#!/bin/bash
set -e
# Set your gems, username and password
gems="bundler"
username="username"
password="password"
apt update -y
apt upgrade -y
apt install -y ruby2.3 ruby2.3-dev nginx fcgiwrap apache2-utils
echo "${password}" | htpasswd -ic /etc/nginx/.htpasswd "${username}"
gem install "${gems}"
mkdir -p /srv/website.com/static
mkdir -p /srv/website.com/app
cat << EOF | tee /etc/nginx/sites-available/default
server {
server_name "";
listen 80;
listen [::]:80 default_server ipv6only=on;
root /srv/website.com/static;
location /app/ {
auth_basic "Protected";
auth_basic_user_file /etc/nginx/.htpasswd;
fastcgi_pass unix:/var/run/fcgiwrap.socket;
fastcgi_param SCRIPT_FILENAME /srv/website.com/\$fastcgi_script_name;
include fastcgi_params;
}
}
EOF
cat << EOF | tee /srv/website.com/app/app.rb
#!/usr/bin/env ruby
require "cgi"
cgi = CGI.new
cgi.out("status" => "OK", "type" => "text/plain", "connection" => "close") do
"Hello!"
end
EOF
chown www-data:www-data /srv/website.com/app/app.rb
chmod +x /srv/website.com/app/app.rb
service nginx restart
curl --user "${username}:${password}" http://localhost/app/app.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.