Rails+passenger+nginx run app with url without :port - ruby-on-rails

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>

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

grape api with subdomain does not work on my nginx server

I have myapp.com for my main app, and api.myapp.com for api. Everything works fine and dandy at local development that's been serve with pow, however when I try to test on my nginx server api.myapp.com/v1/products/1 gives me a 404. (api.myapp.com redirects to myapp.com which is expected due to DNS setup)
I'm using, passenger+nginx, rails and grape-api, here are my setup:
routes.rb
constraints subdomain: 'api' do
mount API::Base, at: '/'
end
nginx conf
server {
listen 80;
listen [::]:80;
server_name myapp.com www.myapp.com api.myapp.com;
passenger_enabled on;
rails_env production;
root /path/to/myapp.com;
error_page 500 502 503 504 /50x.html;
location /50x.html {
root html;
}
}
I have CNAME *.myapp pointing to myapp.com.
I'd probably overlooked something that's fairly basic and fundamental, can someone point me to the right direction. Much appreciated.
Add 2 server blocks..
server {
listen 80 default_server;
server_name app.com;
...
}
server {
listen 80;
server_name subdomain.app.com;
...
}

Serving multiple Rails apps with passenger + Nginx on a single domain

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

Digitalocean - More than one application running on the same droplet?

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

403 error with nginx + passenger + rails 3

I have simple application which works well on Apache but gives me error 403 after moving to Nginx.
Here is my configuration:
server {
server_name myapp.com;
access_log off;
root /home/www/myapp/public;
autoindex on;
passenger_enabled on;
rails_env production;
}
Nginx is running from www-data user which has r+x permissions to all the folders on the path to the application.
Nginx is 0.8.54 and Passenver is 3.0.5.
Any ideas what can be wrong?
Obviously no reasonable errors in nginx log file (I increased logging level to maximum) and also nothing in rails log files.
You're missing the http port:
server {
listen 80;
...
}

Resources