How to add a second app to Phusion Passenger? - ruby-on-rails

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

Related

SSL rails nginx

I am trying to install a SSL certificate that I recently acquired from GoDaddy. My web application is on Rails 4.2.6 and I am using an Ubuntu Server 14.04. I am also using Phusion Passenger 5.0.28 and Nginx. I don’t know if it makes any difference, but I launched the instance using AWS’ EC2.
I created a combined file using the two .crt files sent by GoDaddy.
When I edit my application.rb file:
config.force_ssl = true
I receive the following error:
ERR_CONNECTION_TIMED_OUT
There are two files that I have tried editing, with not success so far:
nginx.conf. The server block currently look like this:
server {
listen 443 ssl;
server_name localhost;
ssl_certificate /var/www/primeraraiz5/primeraraiz_combined.crt;
ssl_certificate_key /var/www/primeraraiz5/primeraraiz.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location / {
root html;
index index.html index.htm;
}
}
include /etc/nginx/sites-enabled/*;
rails.conf (in a sites-available directory; which is “symbolically linked” to the sites-enabled directory ). The server block looks like this:
server {
listen 443 ssl;
passenger_enabled on;
passenger_app_env production;
root /var/www/primeraraiz5/public;
server_name 52.39.200.205 primeraraiz.com;
}
server {
server_name www.primeraraiz.com;
return 301 $scheme://primeraraiz.com$request_uri;
}
I don’t know if I am doing something wrong in these files or if I should change any settings at AWS or with the company that currently hosts my domain.
Thanks a lot for your help!
There are a couple of things to do to your configuration.
The first is the server block containing the redirect. Since you haven't provided us with a server that's listening on port 80, I assume that you want to redirect all requests to http://www.primeraraiz.com; to HTTPS. If so, replace $scheme with https so that your block looks as follows:
server {
server_name www.primeraraiz.com;
return 301 https://primeraraiz.com$request_uri;
}
Next, the SSL offloading needs to happen in the server block from which you're serving. In your case, you're offloading SSL for server name localhost, and not for primeraraiz.com which is what I assume you're trying to do. So copy the SSL parameters of your first server block to the one that has server name primeraraiz.com to end up with:
server {
listen 443 ssl;
server_name 52.39.200.205 primeraraiz.com;
ssl_certificate /var/www/primeraraiz5/primeraraiz_combined.crt;
ssl_certificate_key /var/www/primeraraiz5/primeraraiz.com.key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
passenger_enabled on;
passenger_app_env production;
root /var/www/primeraraiz5/public;
}

Running multiple rails app using passenger

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.

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;
}

Deploying a Rails app to a sub-URI with Passenger and Nginx?

I am already deployed my Rails app with Passenger and Nginx and it's working fine.
Below is my servier configuration:
server {
listen 80;
server_name localhost;
location / {
root /var/www/demo/public;
passenger_enabled on;
rails_env production;
}
Now I want to deploy a second app to a sub URI. Here the documentation is a little unclear.
Could anyone please suggest me what will be the next configuration?
Below is the configuration I am using for my second (Sinatra) application:
location /log {
root /var/www/logger/public;
passenger_base_uri /log;
passenger_enabled on;
}
I am getting "404 Not Found". Please suggest what I am missing here.
Finally it's working!
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:
ln -s /var/www/logger/public /var/www/demo/test
Thanks for all your help.
Add ^~ before the sub-directory:
location /log
To:
location ^~ /log

Multiple Ruby apps (Rails and Sinatra) deployed using Passenger for Nginx?

I have two Ruby applications, one is under Rails and the another is under Sinatra.
How can I deploy both these apps in Nginx and Passenger with one in the root ("localhost:3000") and the other in subroot ("localhost:3000/test")?
The Rails application is running with this configuration. Everything seems to work OK:
server {
listen 80;
server_name localhost;
location / {
root /var/www/demo/public;
passenger_enabled on;
rails_env production;
}
location /test/ {
root /var/www/test/public;
passenger_base_uri /test/;
proxy_pass http://10.0.3.12:80/test/;
passenger_enabled on;
}
I am not able to access the second application.
The server returns 404 for the second app and the first app is still running.
I believe you need to define local servers, that only listen on local port and define your passenger apps there. Your actual server listening on port should only act as proxy.
server {
listen localhost:8181;
server_name test_app;
root /var/www/test/public;
passenger_enabled on;
}
server {
listen localhost:8182;
server_name demo_app;
root /var/www/demo/public;
passenger_enabled on;
rails_env production;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://localhost:8182/;
}
location /test/ {
proxy_pass http://localhost:8181/;
}
}
I didn't have chance to test this config, so it might have some minor flaws, but it should be correct in high-level terms.
In nginx.conf:
server {
listen 80;
server_name localhost;
location / {
root /var/www/new/public;
passenger_enabled on;
rails_env production;
}
location /test {
root /var/www/demo;
passenger_base_uri /test;
passenger_enabled on;
}
Add a soft link:
ln -s /var/www/loggerapp/public /var/www/new/test

Resources