This workshop will be retired on May 1, 2025.
Heads up! To view this whole video, sign in with your Courses Plus account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Rails Servers with Unicorn and Nginx!
You have completed Rails Servers with Unicorn and Nginx!
Let's set up Nginx to forward traffic that it receives on port 80 to our Rails app.
You can test this out either on an actual Ubuntu Linux server at your web hosting company, or you can use a virtual machine.
To install Nginx, connect to your server via SSH, and run:
sudo apt-get install nginx
At this point you should be able to type your server's address into your browser, and see a "Welcome to Nginx" pate.
In your Rails app directory, edit config/nginx.conf
:
server {
listen 80 default;
root /home/deploy/guestbook/public;
try_files $uri/index.html $uri @unicorn;
location @unicorn {
proxy_pass http://localhost:3000;
}
}
Run the following commands on your server:
sudo ln -s /home/deploy/guestbook/config/nginx.conf /etc/nginx/sites-enabled/guestbook
sudo rm /etc/nginx/sites-enabled/default
sudo service nginx restart
In your Rails app directory, edit .rbenv-vars
, and remove the RAILS_SERVE_STATIC_FILES
line, leaving only SECRET_KEY_BASE
.
Then run:
sudo service nginx restart
cd ~/guestbook
RAILS_ENV=production bin/rails server
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up