Rails¶
The OpenLiteSpeed Rails One-Click app automatically installs performance web server OpenLiteSpeed, Ruby and Rails. This image is still in beta! OpenLiteSpeed features easy setup for SSL and RewriteRules. OLS is flexible and also supports Python and NodeJS apps, as well as CMSs like WordPress.
Quick Start¶
Step 1.¶
Use the "OpenLiteSpeed Rails 1-Click app" to create a Droplet with any plan you want. Click here to create an account and get a $100 Digital Ocean credit.
Use the "OpenLiteSpeed Rails app" to create a server with any plan you want. Click here to create an account and get a $100 Vultr credit.
Use the "Deploy OpenLiteSpeed Rails" to create a server with any plan you want. Click here to create an account
- Log into the Google Cloud Platform and click Launch a VM instance on Compute Engine.
Method 1. Through Subscribe
- Subscribe to Rails
- Click Continue to Launch and Launch
Method 2. Through EC2 console
- Open the Amazon EC2 console
- Locate the product by searching for "Rails With OpenLiteSpeed" from AWS Marketplace
- Click Select,Continue,Preview and launch (the default is the most recent version)
- Log into the Azure Portal and click Image Link.
- Click the GET IT NOW and Create buttons
- Choose any server plan you'd like to use, and create the server
Use the "OpenLiteSpeed Rails" from Marketplace to create an ECS instance with any plan you want.
- Log into hPanel
- Navigate to the Operating System page from the sidebar
- On the Change Your Operating System section, select OS with Control Panel and choose the Rails/OpenLiteSpeed template.
Step 2.¶
An interactive script that runs will prompt you for your domain or subdomain:
Please input a valid domain:
Please verify it is correct. [y/N]
Enter your root domain only. The system will automatically add the www
subdomain as well.
Note
You can press CTRL+C and continue to SSH, but the prompt will open again the next time you log in. It will continue to do so until you finish the whole setup.
If your domain is already pointed to this server, you will have the option of automatically applying Let's Encrypt SSL. Enter y
and your email address to complete the process:
Do you wish to issue a Let's encrypt certificate for this domain? [y/N]
Please enter your E-mail:
Please verify it is correct: [y/N]
Once finished, you should see Certificate has been successfully installed...
You can force HTTPS rules to be applied:
Do you wish to force HTTPS rewrite rule for this domain? [y/N]
Complete the process by pressing Y
:
Do you wish to update the system which include the web server? [Y/n]
You should not be prompted to initiate this setup again.
Step 3.¶
Visit the default script by entering http://Server_IP
on your browser and you should see Yay! You’re on Rails!
default page.
Start editing the Rails project here
/usr/local/lsws/Example/html/demo
Optional but recommended:¶
Update system software.
sudo apt update && sudo apt upgrade -y
Your system is installed and ready to use!
Components¶
The OpenLiteSpeed Rails 1-Click Droplet installs several packages and performs other actions on your system.
Package Installation¶
Component | Version |
---|---|
Linux | Ubuntu 24.04 |
rbenv | Latest from rbenv Repo |
Ruby | Latest from rbenv Repo |
gem | Latest from rubygem Repo |
Bundler | Latest from gem |
Rails | Latest from gem |
OpenLiteSpeed | Latest from LiteSpeedtech Repo |
Node.js | Latest from APT |
NPM | Latest from APT |
Certbot | Latest from Certbot’s PPA |
Other Actions¶
- Enables the UFW firewall to allow only SSH (port 22), HTTP (port 80) and HTTPS (port 443) access.
- Runs
rails generate controller welcome index
command to create welcome files and route - Adds
get "/", to: "rails/welcome#index"
toconfig/routes.rb
file - Adds a
/
app context from OpenLiteSpeed > Example Virtual Host so web server can handle the traffic for Rails
How to Access the Installed Software¶
From a terminal on your local computer, connect to the server as root, like so:
ssh root@192.0.2.0
Be sure to substitute the server’s public IP address for 192.0.2.0
.
Web Server Control Panel Access¶
Get the WebAdmin admin password:
cat .litespeed_password
cat /home/ubuntu/.litespeed_password
cat /home/ubuntu/.litespeed_password
Visit https://use_your_droplet_ip:7080
to access WebAdmin in a browser.
By default, WebAdmin uses port 7080. To allow access to 7080 from your IP(e.g. 192.0.2.0):
ufw allow from 192.0.2.0 to any port 7080
ufw allow 7080
We suggest turning this port off once you've finished setup:
ufw delete allow 7080
Optional Setup¶
Enable HTTPS¶
Setting up an SSL certificate enables HTTPS on the web server, which secures the traffic between the server and the clients connecting to it. Certbot is a free and automated way to set up SSL certificates on a server.
Step 1. Register Domain¶
To use Certbot, you’ll need a registered domain name and DNS records:
-
An A record from the domain (e.g.,
example.com
) to the server’s IP address -
An A record from the domain prefaced with
www
(e.g.,www.example.com
) to the server’s IP address.
Step 2. Add Domain to Listener¶
Navigate to OpenLiteSpeed WebAdmin Console > Listeners, and add Your Domain to HTTP/HTTPS.
Step 3. Certbot¶
Once the DNS records are set up, you can generate the SSL certificate. Be sure to substitute the correct domain name in the following command:
certbot certonly --webroot -w /var/www/html/ -d example.com -d www.example.com
/etc/letsencrypt/
Step 4. Set SSL for HTTPS¶
Navigate to OpenLiteSpeed WebAdmin Console > Listeners > SSL, and edit the following three items:
- Private Key File =
/etc/letsencrypt/live/example.com/privkey.pem
- Certificate File =
/etc/letsencrypt/live/example.com/fullchain.pem
- Chained Certificate =
Yes
Save and perform a Graceful Restart.
Now your server should support TLS1.1, TLS 1.2, and TLS 1.3.
Step 5. Redirect HTTP to HTTPS¶
HTTPS traffic on port 443 is already allowed through the firewall. After you set up HTTPS, you can optionally rewrite all HTTP traffic to HTTPS.
Add the following rules to OpenLiteSpeed WebAdmin Console > Virtual Hosts > Rewrite > Rewrite Rules
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
Method for Uploading Files¶
You can serve files from the web server by adding them to the web root using SFTP or other tools.
Frequently Asked Questions¶
How do I Reset my Web Server WebAdmin Password?¶
If you forget your password, you may run the following command to reset it:
/usr/local/lsws/admin/misc/admpass.sh
It will ask for the WebAdmin username, which should be admin
. Then, enter your new password.
How do I Create Additional Virtual Hosts?¶
This method will automatically set up Listener/VirtualHost/Force SSL/Let's Encrypt/WordPress.
Interactive mode
wget https://raw.githubusercontent.com/litespeedtech/ls-cloud-image/master/Setup/vhsetup.sh
chmod +x vhsetup.sh
bash vhsetup.sh
/bin/bash <( curl -sk https://raw.githubusercontent.com/litespeedtech/ls-cloud-image/master/Setup/vhsetup.sh )
CLI mode
wget https://raw.githubusercontent.com/litespeedtech/ls-cloud-image/master/Setup/vhsetup.sh
chmod +x vhsetup.sh
bash vhsetup.sh -d www.example.com -le admin@example.com -f -w
/bin/bash <( curl -sk https://raw.githubusercontent.com/litespeedtech/ls-cloud-image/master/Setup/vhsetup.sh ) -d www.example.com -le admin@example.com -f -w
-
Please be sure that your domain is already pointing to the server when using
-le YOUR_EMAIL
-
Please be sure that your environment has php/sql service/sql root password when using
-w
By default, OpenLiteSpeed has an example virtual host already created. You can create more virtual hosts if you like. See Create Virtual Hosts on OpenLiteSpeed.
How do I upgrade OpenLiteSpeed to latest stable version?¶
OpenLiteSpeed was installed from the LiteSpeed repository, so you can simply use the system update to update OpenLiteSpeed to the latest stable version.
$ sudo apt update && sudo apt upgrade openlitespeed -y
How do I Fix Blocked Host Error?¶
There are two ways to fix a blocked host error: whitelist the hostname, or disable the check. (As seen on StackOverflow.)
Whitelist the Hostname¶
Add the following pattern to the config/environments/development.rb
file (replace hostname
with the hostname you wish to allow):
config.hosts << "hostname"
Disable the Check¶
Disable the check for all environments by adding the following pattern to the config/application.rb
file:
config.hosts = nil
How do I Run Rails Server?¶
Since the image comes with the OpenLiteSpeed web server already, we did not install an extra webpacker package. You can do so with the following steps:
- Install yarn package
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list sudo apt update sudo apt install yarn -y
- Install webpacker package
rails webpacker:install
- Allow firewall port 3000
ufw allow 3000
- Start built-in web server
rails server -b 0.0.0.0
How do I upgrade to LiteSpeed Enterprise?¶
This script will:
-
Generate LiteSpeed Enterprise config file from OpenLiteSpeed config
-
Backup OpenLiteSpeed config and uninstall OpenLiteSpeed
-
Install LiteSpeed and load the config file
/bin/bash <( curl -sk https://raw.githubusercontent.com/litespeedtech/ls-cloud-image/master/Setup/ols2ent-v2.sh )
Note
We recommend you to run and test this script on a test server first. Get help by using the -H
parameter for more information including how to revert back to OpenLiteSpeed if needed.
How to cache the site with LSCache Rules¶
Visit LSCache Without a Plugin doc
We can put following example rules to the OLS Web Admin > Virtual Hosts > Context > App Server context > Rewrite Rules:
CacheLookup on
RewriteCond %{REQUEST_URI} !/admin/
RewriteRule .* - [E=cache-control:max-age=120]
And with that, you have just enabled caching on your site. All pages that are not in the admin subdirectory, will be cached publicly for two minutes.
API Creation¶
In addition to creating a Droplet from the Openlitespeed Rails 1-Click application using the control panel, you can also use the DigitalOcean API.
The following example creates an Openlitespeed Rails 20.04 Droplet called “My-Droplet” in the NYC3 datacenter, with 1 GB RAM:
curl -X POST "https://api.digitalocean.com/v2/droplets" \ -d'{"name":"My-Droplet","region":"nyc3","size":"s-1vcpu-1gb","image":"litespeedtechnol-openlitespeedrai-20-04"}' \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json"
In addition to creating an instance from the Rails using the AWS Management Console, you can also use the AWS Command Line Interface.
The following example creates an t2.micro Instance with Rails AMI:
Please replace XXX to your own settings.aws ec2 run-instances --image-id ami-08589685e56457895 \ --subnet-id subnet-XXXXXXX \ --security-group-ids sg-XXXXXXXXXXXXXX \ --count 1 \ --instance-type t2.micro \ --key-name XXXXXX \ --query "Instances[0].InstanceId"
Get the exact name of the WordPress image from LiteSpeed's project, gc-image-pub
:
gcloud compute images list --project=gc-image-pub --filter="name ~ 'openlitespeed-rails'"
Create an instance, replacing INSTANCE_NAME
with the name of your choice, and IMAGE_NAME
with the name obtained from the previous command:
gcloud compute instances create INSTANCE_NAME --image-project=gc-image-pub --image=IMAGE_NAME
The first time you launch, you may need to accept the marketplace terms using the following command:
Find the release version you prefer:Get-AzureRmMarketplaceTerms \ -Publisher "litespeedtechnologies" \ -Product "openlitespeed-rails" \ -Name "openlitespeed-rails" \ | Set-AzureRmMarketplaceTerms -Accept
Launch VM from that image:az vm image list \ --location westus \ --publisher litespeedtechnologies \ --offer openlitespeed-rails \ --all \ --output table
az vm create \ --resource-group your-group \ --image litespeed_technologies:openlitespeed-rails:rails:3.0.1 \ --name myVM \ --admin-username azure
Feel free to replace resource-group
, image version
, name
, admin name
, --generate-ssh-keys
and more options with your own preferences.
Please check the Elastic Compute Service CLI Samples