Running multiple rails app using passenger - ruby-on-rails

I am hosting a Rails app using passenger and nginx.
I have an nginx.conf with a working server block for the first app that looks somewhat like this.
server {
listen 80;
server_name app1.example.com www.app1.example.com;
passenger_enabled on;
root /home/ec2-user/app1/public;
}
However, I want to deploy a second rails app and on the same nignx.conf wrote:
server {
listen 80;
server_name app2.example.com www.app2.example.com;
passenger_enabled on;
root /home/ec2-user/app2/public;
}
I think there is a conflict with the the ports but I am having trouble finding answers to solving this.

Related

cannot assess rails app on amazon ec2

I'm using Amazon EC2 and tried to deploy a rails project.
I have install nginx/passenger and successfully made nginx server run.
I started my rails project with name "forfun"
then I set the root of nginx to /home/ubuntu/rails/forfun/public
I initialized a file named "index.html", then I could see the page in browser
(http://[my ip]:80)
However, what i really wanna see is the welcome page of rails app.
I tried do remove index.html and see what i got. I saw 404 Forbidden error.
/var/log/nginx/error.log reveals that directory index of "/home/ubuntu/rails/forfun/public/" is forbidden
What step i actually missed?
by the way, do i need to do "rails server" while nginx is running?
ps:
(1) /opt/nginx/conf/nginx.conf
http {
passenger_root /usr/local/rvm/gems/ruby-2.3.0/gems/passenger-5.0.26;
passenger_ruby /usr/local/rvm/gems/ruby-2.3.0/wrappers/ruby;
...
server {
listen 80;
server_name 52.196.XX.XXX;#my amazon public ip
root /home/ubuntu/rails/forfuni/public;
}
(2)/etc/nginx/sites-enabled/default
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /home/ubuntu/rails/forfun/public;
index index.html index.htm;
}
Try adding /etc/nginx/sites-enabled/default
server {
listen 80 default_server;
server_name 52.196.XX.XXX;#my amazon public ip;
passenger_enabled on;
passenger_app_env development; #or whatever rails env you want.
The whole process of deploying a rails app using nginx/passenger is documented here. See the nginx section.
https://www.digitalocean.com/community/tutorials/how-to-deploy-a-rails-app-with-passenger-and-nginx-on-ubuntu-14-04

Deploy multiple Rails applications on a single EC2 server

I have two rails applications on a single EC2 machine at different locations. I would like to have app1.domain1.com to point to one of them while app1.domain1.com to point to another.
I have two records in Route53 to point app1.domain1.com and app2.domain1.com to same IP address and had nginx config route
server {
listen 80;
server_name app1.domain1.com;
root <path_to_app1>;
passenger_enabled on;
}
server {
listen 80;
server_name app2.domain1.com;
root <path_to_app2>;
passenger_enabled on;
}
how ever it appears that even when i try app2.domain1.com it is taking me to app1.

Issue with Nginx redirecting to Rails app

So, I have a domain: coolapp.com Now I want to make it so I can have two subdomains, such as game.coolapp.com and sports.coolapp.com. I have two server configurations in the nginx config as follows:
server {
listen 80;
server_name sports.coolapp.com;
location / {
root /home/deployer/Sports/current/public;
index index.php;
}
passenger_enabled on;
}
server {
listen 80;
server_name game.coolapp.com;
location / {
root /home/deployer/Game/current/public;
index index.php;
}
passenger_enabled on;
}
For some reason, both of these domains are redirecting to the 'sports' app. They SHOULD each by redirecting to their own application, but are interfering with each other.
I am running the Sports app via passenger, with something like 'passenger start --port 80', and I'm running the second app with 'passenger start --port 81'. Should I be running these with different arguments, or what exactly is causing the issue here?
Your problem is not quite clear to me. I am making the following assumptions in my answer.
You are running 3 apps all on Phusion with Nginx.
Nginx configuration is pretty straight forward. Probably you have configured nginx.conf properly because you main app is working.
The next thing you should do is read the phusion passenger doc on how to run Rails on subdomain. Reading https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html#deploying_a_rack_app will give you a lot of insight. I recommend you read the entire doc.
I think there is a problem in the way you have configured your nginx.conf and how you are starting you phusion passenger (BTW I think you do not even have to start the phusion passenger explicitly and that NGINX should take care of that)
In your nginx configuration you are listening to port 80 and in your phusion passenger command you are asking it to listen to port 81 and 82. Change you nginx configuration to read like (BTW it is better to use sites-available & site-enabled for this)
server {
listen 80;
server_name sports.coolapp.com;
root /home/deployer/Sports/current/public;
passenger_enabled on;
}
server {
listen 80;
server_name games.coolapp.com;
root /home/deployer/Sports/current/public;
passenger_enabled on;
}
I hope you have configured your subdomains properly. You should double check that as well.
Save changes. Restart Nginx and you should be good to go.

How to add a second app to Phusion Passenger?

I have my Phusion Passenger Nginx configured to as below :
server {
listen 80;
server_name blog.abc.com;
passenger_enabled on;
root /app/public;
}
Im about to host the main site abc.com also in this machine. How can I do that (Its a separate app)? Is it possible to add another server block like this :
server {
listen 80;
server_name abc.com;
passenger_enabled on;
root /app2/public;
}
Phusion Passenger author here. Yes. Just add another virtual host block for the other app. It works exactly as expected.
I configured my second app on sub-uri of first app. Below is the nginx conf and settings what i done.
nginx.conf:
server {
listen 80;
server_name localhost;
location / {
root /var/www/demo/public;
passenger_enabled on;
rails_env production;
}
location /test {
root /var/www/demo;
passenger_base_uri /test;
passenger_enabled on;
}
Then add symbolic link:
ln -s /var/www/logger/public /var/www/demo/test

Nginx for multiple apps with different subdomain

Been trying to search for a time but can't seem to find a solution. I want to set multiple apps in one server via nginx. Current nginx.conf is as follows:
server {
listen 80;
server_name mydomain.co;
root /mydomain/current/public;
passenger_enabled on;
rails_env production;
}
server {
listen 80;
server_name testing.mydomain.co;
root /mydomain-test/current/public;
passenger_enabled on;
rails_env test;
}
It serves up the correct environment (test) but doesn't serve the correct codebase. I checked the directory mydomain-test via ssh and it contains the recent code but is not being served by nginx.
Basically, what I want is:
mydomain.co to serve /mydomain/current/public
testing.mydomain.co to serve /mydomain/current/public
How is this done correctly?
I believe the root directive should be in the location section. I am unsure of the rails directive and passenger_enabled directive but the rest is similar to what I use and works. Might be best to also specify the index script (i have it set to index.php but change as appropriate).
Once you have made the changes be sure to restart nginx.
server {
listen 80;
server_name mydomain.co;
location / {
root /mydomain/current/public;
index index.php;
}
passenger_enabled on;
rails_env production;
}
server {
listen 80;
server_name testing.mydomain.co;
location / {
root /mydomain-test/current/public;
index index.php;
}
passenger_enabled on;
rails_env test;
}

Resources