Is it possible to run more than one Rails application on the same DigitalOcean droplet?
I recommend looking into using Dokku with Docker, which allows you to host applications along side each other. Digital Ocean has a One-click install available. I just started using it and deploying this way, and so far really like it.
Here are some links:
http://reallybusywizards.com/dokku-digitalocean-your-very-own-cheap-heroku-clone/
https://www.andrewmunsell.com/blog/dokku-tutorial-digital-ocean
https://www.digitalocean.com/community/tutorials/how-to-use-the-dokku-one-click-digitalocean-image-to-run-a-node-js-app
Yes you can do this, you just need to configure your application server, I have done this using nginx, is very quiet.
This tutorial is pretty cool to start with the server installer and rails application using Nginx server application:
Tutorial DigitalOcean
After doing this, open the configuration file for nginx:
sudo nano /opt/nginx/conf/nginx.conf
Now just add another block to configure a new application on another port, the default port is always 80. Enter note that port 8080 in this block.
server {
listen 8080;
server_name example.com;
passenger_enabled on;
root /var/www/my_new_rails_app/public;
}
Hope this helps!
YES
I am doing this currently. If your using Apache then in your httpd.conf file simply make two entries pointing to the public folders of two different application. Remember to identify different address for each.
I use phusion-passenger to make rails run with apache and my setup looks like this;
<VirtualHost ####################.com:80>
ServerName ####################.com
DocumentRoot /var/www/html/first_app/current/public/
<Directory /var/www/html/first_app/current/public>
Allow from all
Options -MultiViews
</Directory>
PassengerEnabled on
#RewriteEngine On
#RewriteCond %{HTTPS} on
#RewriteRule (.*) http://www.####################.com%{REQUEST_URI}
SetEnv GEM_HOME /usr/lib/ruby/gems/1.8
</VirtualHost>
<VirtualHost second_app.####################.com:80>
ServerName second_app.####################.com
DocumentRoot /var/www/html/second_app/current/public/
<Directory /var/www/html/second_app/current/public>
Allow from all
Options -MultiViews
</Directory>
PassengerEnabled on
#RewriteEngine On
#RewriteCond %{HTTPS} off
#RewriteRule (.*) https://www.####################.com%{REQUEST_URI}
SetEnv GEM_HOME /usr/lib/ruby/gems/1.8
</VirtualHost>
I had similar problem but #Leandro Figueredo answers didn't work for me.
Below i presenting what i do to achieve this.
Actually i have two website on one droplet.
I configured my server with this tutorial: GoRails How to setup server with Ubuntu 14.04 and nginx
After this configure file /etc/nginx/sites-enabled/default
server {
listen 80;
listen [::]:80 default_server ipv6only=on;
server_name example.com www.example.com;
passenger_enabled on;
rails_env production;
root /home/user/appname/current/public;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
listen [::]:80;
server_name second_site.com www.second_site.com;
passenger_enabled on;
root /home/user/second_app/current/public;
}
Important:
remove default_server; from first server block
Related
I have a single Nginx instance with passenger and would like to serve different Rails apps at different routes. Specifically: /api should serve one app and / should serve a different.
My Rails apps are located at /srv/api/ and /srv/ui on the filesystem.
My Nginx config is currently like this:
user foo;
worker_processes 1;
events { worker_connections 1024; }
http {
passenger_root /usr/lib/ruby/gems/1.8/gems/passenger-4.0.49;
passenger_ruby /home/monolith/.rvm/gems/ruby-2.1.1/wrappers/ruby;
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /srv/ui/public/;
passenger_enabled on;
}
location /api {
root /srv/api/public/;
passenger_enabled on;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
With this config, the API app is being served correctly, but the UI app is not. It returns a 500 error, and there are no error logs in either Nginx or under logs in Rails.
Attempted solutions / debugging
echo 'test' > /srv/ui/public/index.html. This results in a successful render of 'test'
when visiting <hostname>.com/
Changing location / to serve a static index.html using the alias directive instead. This works also.
I saw this solution of symlinking a file inside the / location https://www.chiliproject.org/boards/1/topics/545, but this would be relevant if the API app was not being served.
I suspect this has something to do with interference among passenger instances, but I don't know what the solution is.
We've achieved this before (albeit with Apache - maybe we can work towards a port for Nginx):
#app/apache2/apache2.conf
<VirtualHost *:80>
ServerName *********.co.uk
DocumentRoot /apps/[main_app]/current/public
<Directory /apps/[main_app]/current/public>
Allow from all
Options -MultiViews
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
#Secondry App
Alias /[app_name] /apps/[app_name]/current/public
<Location /[app_name]>
PassengerAppRoot /apps/[app_name]/current
RackEnv production
RackBaseURI /[app_name]
</Location>
</VirtualHost>
In terms of Nginx, you may be able to get away with the following:
#etc/nginx/nginx.conf
http {
server {
listen 80;
server_name yourdomain.com;
#serve your "main" site here
root /srv/ui/public/;
passenger_enabled on;
#serve your "API" app from the location / Alias
location /api {
root /srv/api/public/;
passenger_enabled on;
}
}
}
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.
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.
I have a rails app... I installed chain: nginx+passenger and run rails server. But my trouble is that in browser i must to set up url like:
page.com:3000
but how to use only page.com?
I can't run command passenger start -e=development -p=80 of user restriction....
My nginx conf file is such:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#root /home/prog/OnlineAuto/Shop/public;
#passenger_enabled on;
#access_log logs/host.access.log main;
location / {
root /home/prog/OnlineAuto/Shop/public;
index index.html index.htm;
passenger_enabled on;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
So how can i get my rails app by domain without any port? (but run rails server on 3000 port)
You're trying to start Passenger on the same port that Nginx is using which is likely why you're getting an error.
I'm more familiar with Unicorn, but based on the documentation I've read, you shouldn't have to start Passenger in a separate process. With Passenger installed properly, I think you only need Nginx directives to make it work.
Configure your passenger_root and passenger_ruby in http block in nginx.conf, and then
http {
passenger_root /<path_to_passenger_install>;
passenger_ruby /usr/local/bin/ruby;
server {
listen 80;
server_name page.com;
charset utf-8;
root /www/page.com/public;
passenger_enabled on;
rails_spawn_method smart;
rails_env development;
}
}
If you are using passenger here is what I had to use to get it working on www.mysite.com without using www.mysite.com:80 on a centos server:
In etc/httpd/conf the key was to uncomment the NameVirtualHost *:80 and change the * to my server's IP address. Make sure Listen 80 is uncommented. Also add your ip to the VirtualHost tag. It must be running on port 80, not 8080 or something of your choosing.
NameVirtualHost xx.xx.xx.xx:80
Listen 80
<VirtualHost xx.xx.xx.xx:80>
ServerName www.mysite.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/vhosts/mysite.com/httpdocs/public/
<Directory /var/www/vhosts/mysite.com/httpdocs/public/>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
I have nginx with rewriting working correctly on my server in production.
But when I tried to set the same rule on my local development machine (mac) the rewrite doesn't seem to be working.
I want "universitytutor.local" to redirect to "www.universitytutor.local"
Here is the relevant part of my nginx.conf
server{
listen 80;
server_name universitytutor.local;
rewrite ^/(.*) http://www.universitytutor.local/$1 permanent;
}
server {
listen 80;
server_name www.universitytutor.local *.universitytutor.local;
root /Users/barmstrong/NetBeansProjects/universitytutor/public; # <--- be sure to point to 'public'!
passenger_enabled on;
rails_env development;
}
The page loads correctly whether I type "universitytutor.local" or "www.universitytutor.local" and it does not redirect.
I have the *.universitytutor.local in there because I use subdomains for different cities so I need this, but I want a blank subdomain to redirect to "www".
Any ideas?
Found the solution for this. I was not restarting Nginx correctly so it was not picking up the changes. Doh!
You can restart like this
sudo kill `cat /opt/nginx/logs/nginx.pid `
sudo /opt/nginx/sbin/nginx
or add this to your .bashrc for easier use
alias nginx_restart='nginx_stop; nginx_start'
alias nginx_start='sudo /opt/nginx/sbin/nginx'
alias nginx_stop='sudo kill `cat /opt/nginx/logs/nginx.pid `'