Installing nginx with passenger on Ubuntu 17.04
(The typos will be corrected soon)
This little tutorial explains how to install Nginx with Passenger-support in order to run Ruby on Rails applications on Ubuntu 17.04.
I'm a huge fan of RVM for mangeing Ruby installations, so make sure it's installed.
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
\curl -sSL https://get.rvm.io | bash
rvm install ruby-2.4.1
rvm use default ruby-2.4.1
I'v
e had some problems installing Ruby 2.4.1 on other systems mainly OpenSUSE. Problems occured when compiling the source, and usally the problem were in use use of gcc7-compiler. Installing gcc6 installing Ruby like this usally works:
CC=/usr/bin/gcc-6 rvm install ruby-2.4.1
In order to check if Ruby is installed correct run:
ruby --version
The output should be something like:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
I like to store sourcefiles in ~/src for later use, but you can use whatever directory you want.
cd ~
mkdir src
cd src
wget https://nginx.org/download/nginx-1.12.1.tar.gz
tar -xzf nginx-1.12.1.tar.gz
rm -v nginx-1.12.1.tar.gz
The installation will ask you where you placed the source if you choose option 2. Then you just write the path to the source of nginx. For me it's:
/home/mads/src/nginx
Replace 'mads' with your own username.
That should do it!
The installation installs nginx to /opt/nginx
The configuration file is /opt/nginx/conf/nginx.conf
Logs are stored in /opt/nginx/logs
In order to start nginx run:
sudo /opt/nginx/sbin/nginx
sudo is required as the webserver runs on port 80 which is a system reserved port.
In order to reload the applications without shutting down the server run:
This little tutorial explains how to install Nginx with Passenger-support in order to run Ruby on Rails applications on Ubuntu 17.04.
Ruby installation
I'm a huge fan of RVM for mangeing Ruby installations, so make sure it's installed.
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
\curl -sSL https://get.rvm.io | bash
rvm install ruby-2.4.1
rvm use default ruby-2.4.1
I'v
e had some problems installing Ruby 2.4.1 on other systems mainly OpenSUSE. Problems occured when compiling the source, and usally the problem were in use use of gcc7-compiler. Installing gcc6 installing Ruby like this usally works:
CC=/usr/bin/gcc-6 rvm install ruby-2.4.1
In order to check if Ruby is installed correct run:
ruby --version
The output should be something like:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
nginx download
Nginx doesn't support runtime plugins, so in order to get Passenger support, we have to compile nginx from source with passenger added as a module.
I like to store sourcefiles in ~/src for later use, but you can use whatever directory you want.
cd ~
mkdir src
cd src
wget https://nginx.org/download/nginx-1.12.1.tar.gz
tar -xzf nginx-1.12.1.tar.gz
rm -v nginx-1.12.1.tar.gz
Installing passenger
I'll be using the passenger gem https://rubygems.org/gems/passenger/versions/5.0.28, which makes the installation very easy.
gem install passenger
passenger-install-nginx-module
The installation guide will popup and you'll be able to configure the nginx installation to your needs. I'm using the "2. No: I want to customize my Nginx installation. (for advanced users)" during the installation. By choosing the advanced installation you'll have the option to include other modules as well.
gem install passenger
passenger-install-nginx-module
The installation guide will popup and you'll be able to configure the nginx installation to your needs. I'm using the "2. No: I want to customize my Nginx installation. (for advanced users)" during the installation. By choosing the advanced installation you'll have the option to include other modules as well.
I've never tried the first option, but it should download the source and compile it without further ado. Choose this, if you don't intend to include other modules in the installation. You could properly choose to skip the download section of nginx as well.
The installation will ask you where you placed the source if you choose option 2. Then you just write the path to the source of nginx. For me it's:
/home/mads/src/nginx
Replace 'mads' with your own username.
That should do it!
The installation installs nginx to /opt/nginx
The configuration file is /opt/nginx/conf/nginx.conf
Logs are stored in /opt/nginx/logs
In order to start nginx run:
sudo /opt/nginx/sbin/nginx
sudo is required as the webserver runs on port 80 which is a system reserved port.
In order to reload the applications without shutting down the server run:
passenger-config restart-app
Systemd service
In or
der to have nginx run at start up, you can create a systemd service, which also makes mangeing nginx easier.
sudo touch /lib/systemd/system/nginx.service
sudo nano /lib/systemd/system/nginx.service
Insert the following in the editor:
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/opt/nginx/logs/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -t
ExecStart=/opt/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Ctrl + Shift + V to insert text from clipboard
Ctrl + X to exit nano
In order to enable the newly created service, run:
sudo systemctl enable application.service
Now if everything works correctly, nginx will start during boot and you can manage nginx by:
sudo service nginx start
sudo service nginx restart
sudo service nginx stop
That should do it.
der to have nginx run at start up, you can create a systemd service, which also makes mangeing nginx easier.
sudo touch /lib/systemd/system/nginx.service
sudo nano /lib/systemd/system/nginx.service
Insert the following in the editor:
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/opt/nginx/logs/nginx.pid
ExecStartPre=/opt/nginx/sbin/nginx -t
ExecStart=/opt/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
Ctrl + Shift + V to insert text from clipboard
Ctrl + X to exit nano
In order to enable the newly created service, run:
sudo systemctl enable application.service
Now if everything works correctly, nginx will start during boot and you can manage nginx by:
sudo service nginx start
sudo service nginx restart
sudo service nginx stop
That should do it.
Kommentarer
Send en kommentar