Skip to content

Instantly share code, notes, and snippets.

@46bit
Last active March 21, 2017 05:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save 46bit/6de5694550f04638b7e6 to your computer and use it in GitHub Desktop.
Save 46bit/6de5694550f04638b7e6 to your computer and use it in GitHub Desktop.
Arch Linux and Systemd: Rbenv, Passenger and Nginx

Arch Linux and Systemd: Rbenv, Passenger and Nginx

Rbenv

git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"

Pick a Ruby version from rbenv install -l to install. Then adapt the following command to your version number.

rbenv install 2.2.0
rbenv global 2.2.0

You might need to enlarge swap so this can build Ruby. About 1GB of total memory seems to be needed.

Passenger and Nginx

Passenger has to be compiled into Nginx, unless using it Standalone. To take advantage of not configuring reverse proxying, we recompile (which is easy and quick enough).

gem install passenger
passenger-install-nginx-module

The following sections assume you install nginx to /etc/nginx.

Passenger's installer is well-built so do as it advises. Any suggested permission changes don't make your user files world-readable.

Systemd-starting the new Nginx

Passenger's generic gem install ignores the need to start Nginx and Passenger on boot. To fix this create a simple systemd service to do so, at /etc/systemd/system/nginx.service.

[Unit]
Description=Nginx
After=syslog.target network.target

[Service]
Type=forking
ExecStart=/etc/nginx/sbin/nginx
ExecReload=/etc/nginx/sbin/nginx -s reload

[Install]
WantedBy=multi-user.target

Now set this service to start on boot and (if you like) start it now.

sudo systemctl enable nginx.service
sudo systemctl start nginx.service

Nginx virtual hosts and SSL

If you want to run Passenger for a given virtual host, you need to enable it. You can configure Nginx in /etc/nginx/conf/nginx.conf.

server {
  root /PATH_TO_RUBY_APP/public;
  passenger_enabled on;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment