# Install latest Nginx stable version
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx nginx-extras
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 561F9B9CAC40B2F7
sudo apt-get install apt-transport-https ca-certificates
sudo vim /etc/apt/sources.list.d/passenger.list
deb https://oss-binaries.phusionpassenger.com/apt/passenger trusty main
sudo apt-get update
sudo apt-get install passenger
By default Nginx creates /etc/nginx/nginx.conf
file. This file contains main configuration, that we will let stay as it is now. Better we'll navigate to folder /etc/nginx/sites-available
and create configuration for our example.com site. By default main configuration file reads from these folders: sites-available
and sites-enabled
, but the first one serves only for storing configurations but the second one contains realy executable configs. At sites-available
create file example.com and fill it with something that looks like following:
upstream example {
server 0.0.0.0:3000 max_fails=3 fail_timeout=1s;
keepalive 4;
}
server {
listen 80;
server_name example.com www.example.com;
root /home/deploy/example.com/public;
client_max_body_size 100M;
location / {
proxy_pass http://example;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
Here we create upstream and redirect all requests at location / to the instance of Passenger working on port 3000. Then we need to symlink our config to sites-enabled
:
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com
Don't forget to test your configuration:
sudo nginx -t
And restart service if config is OK:
sudo service nginx restart