Deploying Rails/Passenger via nginx - ruby-on-rails

I'm having a hard time figuring out where I'm going wrong in trying to deploy a Rails app via nginx. Rails is accessible via site.com:3000 (after starting it with rails server), and site.com:80 displays the standard nginx "working, but further configuration required" page. I've spent a few hours trawling the documentation trying to figure our how to get my Rails app accessible at :80 rather than :3000, but to no avail.
I think it's most likely that I'm misunderstanding how nginx, Passenger, and Rails work together, and have therefore configured my nginx.conf incorrectly (one page I found implied that I shouldn't both be using nginx and running rails server). Any and all help is hugely appreciated.
Possibly relevant version numbers:
Rails 4.1.4
Ruby 2.1.2p95
CentOS 6.5
nginx 1.6.0
nginx.conf partial: http://pastebin.com/A3JD09pr

I'm new at this, so it turned out that a couple things were up:
I needed to put export rvmsudo_secure_path=1 in my .bashrc instead of just running it once, following up with source ~/.bashrc in the terminal. This allowed me to run "rvmsudo" commands to start on port 80 rather than the default 3000.
I had both nginx and Rails competing for port 80, so I had to stop nginx's static page server to allow that. Simple as nginx stop.

Related

Domain setting using ruby rails

I am planning to have a web application.
To do so, I studied about ruby and ruby on rails. I am using linux server from amazon clouding system.
I bought a domain from godday, and I put the IP address on DNS setting. When I run 'rails s' command, I can connect to the wep page through port 3000 in such a way that domain.com:3000. However, I cannot directly connect to domain.com. How can I my domain works without port 3000?
And Do I have to run 'rails s' every time to make the wep page work? Actually I tried to use 'rails s &' to make it run in background. But it fails. How can I make the server run even though I am not connected to the linux server?
Thank you!
usually you use rails s just in development. there are quite a few ruby web servers you can choose from for your production environment: puma, passenger or unicorn to name a few.
of course all of them have their own tutorials how to set them up. for starters, i'd go with with passenger because it's integrated with nginx and apache and easily set up.
You need to specify a port, if you don't see the port it can be either 80 (http) or 443 (https).
rails server -p 80
On linux you have to be root to bind to port less than 1000, so just append sudo in front.

Setting up multiple rails apps using nginx and Puma

I have a web server serving multiple Rails applications using a combination of nginx and Passenger. This is pretty straightforward, because the Passenger install sets-up pretty much everything you need to connect to nginx.
I found "Rails app with Puma" that seems to explain how to set up nginx and Puma together. How would this configuration need to be modified in order to serve a second Rails application on the same server?
Also, this guide doesn't say anything about restarting the application automatically if there is a system reboot or some other issue. Is there a way to do that? The nginx + Passenger combo seems to do it by default.

Phusion Passenger / Apache Not Running Correctly on Mac OSX Maverick

After updating to OS X Maverick on my MacBook, my local dev environment was broken - Apache httpd.h file missing on MacOSX after Mavericks Upgrade (** Updated for Yosemite **)
Now after resolving the issues I can't seem to run my local web server on port 80 (localhost).
If I go to 'localhost' I see It works! which is the default apache page.
If I run passenger start I can view my app at localhost:3000 but that's a passenger standalone web server running, not apache.
If I run sudo passenger start -p 80 --user=martin I get the message:
The address 0.0.0.0:80 is already in use by another process,
perhaps another Phusion Passenger Standalone instance.
If you want to run this Phusion Passenger Standalone instance on another port,
use the -p option, like this:
passenger start -p 81
I can't remember what I did when I first set up Rails on my laptop, I'm sure I ran passenger start at the very beginning and didn't need to do it after that and from reading more about it online, apache should run passenger automatically by itself but apache doesn't seem to be doing anything but show the default start page and I don't know why.
I think Maverick created a new httpd.conf but I don't see much difference, I have made sure that the three extra lines running passenger-install-apache2-module returns is at the end of the config file.
The passenger gem is the latest version, Rails version is 2.3.14 and ruby is 1.8.7 so quite old but shouldn't matter I don't think as it worked perfectly on localhost before without having to add port 3000 to the url so just hoping someone with a bit more experience of using Passenger can help.
I've tried reading loads of other questions and forums and also the Phusion Apache documentation.
`
I had the same problem. I restored the previous httpd.conf file in /etc/apache2. The file had been renamed httpd.conf.pre-update. I restarted the server with apachectl restart and all was fine again.
I checked the differences between the old and new httpd.conf files, and they were very small (but crucial):
1) The line to include virtual hosts was commented out.
2) The line to include the PHP module was commented out.
I uncommented both lines and problem solved.

Deploying Rails applications with Passenger and Nginx to VPS (EC2)

I've developed a couple of applications which I'm ready to deploy. To do so, I've configured Capistrano and I'm already able to run cap deploy, which runs properly. However, I'm totally lost as to how to continue from here. My setup is EC2 + Rails 3.2 + Ruby 1.9.3 + Passenger + Nginx (the one Passenger installs first time you try to start it) + Capistrano.
Until now, I just ran passenger start on my app root folder, which would start passenger on port 3000, and I would start the second app on port 3001. Now, what I need is to have this 2 apps under 2 different domains, say www.domain1.com and www.domain2.com.
How am I supposed to start the servers now? I can go to the respective current folders that Capistrano created and run something like passenger start -e production -p 3001 -d and it starts running as a daemon, but, shouldn't capistrano take care of this? All I see is that, on each deploy, it touches the restart.txt file and that forces a "soft restart", which is not enough (as far as I know) if you've changed gems. Shouldn't Capistrano be starting and stopping Passenger, not me?
How do I run the 2 apps on 2 domains? As far as I know, you can't point a domain to a port, and all I've managed to do now is to run 1 of the applications by running Passenger on port 80 with rvmsudo, but of course this only works for 1 application. After searching a bit I've found something about Nginx Virtual Servers. How do you do this? I mean, I have never touched anything specific to Nginx, just Passenger! Am I supposed to forget about Passenger and deal with Nginx as a service? How?
Thanks in advance!
I believe to start servers there's a specific cap command to start servers, but i don't know much about capistrano, just played with it a little bit before.
As for the second part, this is where nginx takes part, nginx will handle forwarding each domain to the specific port, using proxy_pass, take a look at this example
server {
server_name: example1.com;
proxy_pass: http://127.0.0.1:3000;
}
server {
server_name: example2.com;
proxy_pass: http://127.0.0.1:3001;
}

Starting Rails server on boot on CentOS

I'm pretty new to rails and trying to figure things out, I looked online but not much luck.
I have some servers that are running rails on startup without using rc.local at all, but I can't figure out why.
All I need is for rails to start on boot in production mode on port 80 (instead of 3000, as the rest of the servers also start on port 80).
Any ideas?
ATM relaying on webrick
Have a look at setting up nginx with ruby enterprise edition.
Check out Phusion Passenger. It supports both the standard Apache web server and Nginx web server.
http://www.modrails.com/

Resources