This repository has been archived by the owner on Mar 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 283
Serving with Nginx
Andrew Wippler edited this page Jan 11, 2016
·
2 revisions
We recommend serving OneBody with Apache, but only because that's what we know and are willing to lend help with. 😜
For those who wish to implement nginx, several key factors have to be implemented. The first is ensuring the rails server is running. This can be done via start-up script like the one below:
#!/bin/bash
cd /var/www/onebody
bundle exec rails server -d
OneBody uses the thin
webserver to run Ruby code as it is much faster than WEBrick. Now that rails is running, we can then start nginx with the following /etc/nginx/sites-enabled/onebody.conf
by issuing a service nginx start
.
upstream onebody {
# this is the IP of the thin webserver
server 127.0.0.1:3000;
}
server {
# default_server will respond to any ip address and host name.
# If you plan on running more websites, re-think the default_server directive.
listen 80 default_server;
server_name onebody;
# Tell Nginx where your app's 'public' directory is
root /var/www/onebody/public;
location @onebody {
internal;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://onebody;
}
location / {
# We are telling nginx here to access the file directly.
# If it cannot be found, send it on to the thin webserver
try_files $uri/index.html $uri @onebody;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|woff|woff2)$ {
expires max;
log_not_found off;
}
}