Created
April 17, 2018 01:27
-
-
Save benubois/02c6e4fdae6bc2c04b7869e1f3bff385 to your computer and use it in GitHub Desktop.
ruby cgi server setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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