Passenger, Nginx, and Capistrano - Passenger not launching Rails app at all - ruby-on-rails

Essentially, my route is working perfectly, Passenger seems to be loading - all is hunky-dory. Except that nothing Railsy happens. Here's my Nginx log from starting the server to the first request (ignore the different domain/route - it's because I haven't moved the new domain over yet, and it's returning a 403 error because there's no index file in the public folder):
[ pid=24559 file=ext/nginx/HelperServer.cpp:826 time=2009-11-10 00:49:13.227 ]:
Passenger helper server started on PID 24559
[ pid=24559 file=ext/nginx/HelperServer.cpp:831 time=2009-11-10 00:49:13.227 ]:
Password received.
2009/11/10 00:49:53 [error] 24578#0: *1 directory index of "/var/www/***/current/public/" is forbidden, client: 188.221.195.27, server: ***, request: "GET / HTTP/1.1", host: "***"
2009/11/10 00:49:54 [error] 24578#0: *1 open() "/var/www/***/current/public/favicon.ico" failed (2: No such file or directory), client: 188.221.195.27, server: ***, request: "GET /favicon.ico HTTP/1.1", host: "***", referrer: "***"
Someone on the RubyOnRails IRC channel suggested that it might be a webserver permissions problem. I had a suspicion that it might be a filesystem permission problem, but then Nginx runs as www-data and Passenger as root.
I can load static files from within the public directory fine, but no Rails application is being launched. Does anyone have an idea? My head is gradually melting away figuring this one out!
Edit: Here's the vhost file:
server {
listen 80;
server_name ***;
passenger_enabled on;
location / {
root /var/www/***/current/public;
index index.html index.htm;
}
#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;
}
}

Problem solved, I am a spanner.
I had 'passenger_enabled on;' inside 'location /' not 'server'. I hereby hand in my coding hands.

Related

Error during WebSocket handshake: Unexpected response code: 502

I have Rails app on Digital Ocean (Ununtu 18.04 + nginx + passenger + Capistrano). I have chat functionality inside my app based on Action Cable. On my local everything works without problem, but on production i get next error: Error during WebSocket handshake: Unexpected response code: 502.
As i understand something wrong with Action Cable configuration. But everything done as in tutorials so i now really confused and don't know where i should looking for evil. Please help!
production.rb file
config.action_cable.url = '/cable'
config.action_cable.allowed_request_origins = ['http://example.com']
cable.yml file
production:
adapter: redis
url: redis://redis.exmaple.com:6379
messages.coffee file
jQuery(() ->
App.messages = App.cable.subscriptions.create {channel: 'MessagesChannel', id: $('#conversation_id').val() },
received: (data) ->
jQuery('#new_message')[0].reset()
jQuery('#chat').append data.message
)
messages_channel.rb file
class MessagesChannel < ApplicationCable::Channel
def subscribed
stream_from "conversation_#{params[:id]}"
end
end
/etc/nginx/sites-enabled/myapp file
server {
listen 80;
listen [::]:80;
server_name example.com;
root /home/deploy/myapp/current/public;
passenger_enabled on;
passenger_app_env production;
location /cable {
passenger_app_group_name myapp_websocket;
passenger_force_max_concurrent_requests_per_process 0;
}
# Allow uploads up to 100MB in size
client_max_body_size 100m;
location ~ ^/(assets|packs) {
expires max;
gzip_static on;
}
}
In nginx i have a lot of such errors:
2019/07/18 07:37:47 [error] 25500#25500: *9088 upstream prematurely closed connection while reading response header from upstream, client: 117.102.40.105, server: example, request: "GET /cable HTTP/1.1", upstream: "passenger:unix:/tmp/passenger.q4FqjUT/agents.s/core:", host: "example.com"
Of course everywhere example.com is replaced with my real domain name.
I have found the problem. It was in redis url in configuration. In each tutorial it write to use next code:
production:
adapter: redis
url: redis://redis.example.com:6379
But looks that it is mistake and correct will be next code:
production:
adapter: redis
url: redis://localhost:6379
So instead you domain should be used localhost. Hope, this will help somebody and will save a lot of time)

rails looking into public folder for all URLs in production mode

My rails app isn't working all of a sudden in production mode as every URL is looking into public folder rather than invoking controller actions, resulting errors like
2016/11/16 11:48:23 [error] 25138#0: *9 open() "/var/www/html/looted/public/admin/products" failed (2: No such file or directory), client: 125.99.106.246, server: www.looted.com, request: "GET /admin/products HTTP/1.1", host: "www.looted.com"
When I run it in development, everything works fine. Am running passenger on nginx server with below configuration
server {
listen 80;
server_name looted.com www.looted.com;
root /var/www/html/looted/public;
passenger_enabled on;
client_max_body_size 250M;
passenger_app_env production;
}
I am using Rails 4.2.4, ruby 2.2.1p85, passenger-5.0.29
Can anybody point me the direction to check what's wrong?
Thanks in advance

Nginx shows public directory content instead of executing Rails App

I am trying to execute my Rails Application on Nginx and Passenger but it shows the public directory content instead of executing the application.
server {
server_name 104.236.218.36;
listen 80 default_server;
root /var/www/noise/public;
passenger_enabled on;
rails_spawn_method smart;
rails_env production;
autoindex on;
}
If i remove autoindex on; i am getting the following error.
2015/02/02 06:16:06 [error] 13528#0: *3 directory index of "/var/www/noise/public/" is forbidden, client: 122.178.204.27, server: 104.236.218.36, request: "GET / HTTP/1.1", ho$
The config you show works ok for me, but maybe you have something else set wrong outside the system scope.
You could also specify the Rails app directory try adding:
passenger_app_root /var/www/noise;

rails fallback to assets pipeline

I'm trying to deploy a rails4 (ruby-2.0.0) app to my server. Almost all of my assets are precompiled, and served by nginx.
One js.erb, generates a dynamic html-list, by getting models from my database. This asset can't be precompiled, because it must remain dynamic.
I'm excluding this asset from asset.precompile, and turned on
config.assets.compile = true
to fall back to the asset pipeline, for this one asset.
In my local production env, everthing is working, but on my server (nginx, unicorn) the asset pipeline fall back won't work. I get a simple 404 Error
nginx error log:
2013/09/13 08:54:54 [error] 27442#0: *58 open() "/XXX/current/public/assets/rails_admin/rails_admin_switchable-051203ae1d7aca2c08092e5c92bcdf15.js" failed (2: No such file or directory), client: XXX, server: , request: "GET /assets/rails_admin/rails_admin_switchable-051203ae1d7aca2c08092e5c92bcdf15.js HTTP/1.1", host: "XXX", referrer: "http://XXX/admin"
unicorn and rails don't show any errors.
Any ideas, how I can solve this?
best,
Franz
It looks like your nginx server definition isn't properly integrated with your app server. It should be configured to pass a request that doesn't match a physical file on to the app server.
Here is a standard configuration for a rails app living in /app with nginx via a unicorn/UNIX-socket integration:
upstream app_server {
server unix:/tmp/nginx.socket fail_timeout=0;
}
server {
listen <%= ENV["PORT"] %>;
server_name _;
keepalive_timeout 5;
# path for static files
root /app/public;
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
# Rails error pages
error_page 500 502 503 504 /500.html;
location = /500.html {
root /app/public;
}
}
If your asset pipeline compiles to /app/public/assets you should be good to go.

Nginx doesn't recognize my Rails 3 application

I have set up nginx + REE + passenger on my Linode VPS, which has been running great for past six month, both for Rails 2.3.x and Sinatra applications.
However this week I tried to add Rails 3 application to the stack, and I keep on getting 404 Not Found. Logs show that nginx doesn't recognize Rails application and is trying to serve it as static.
2010/11/29 23:44:44 [error] 12464#0: *29 "/var/app/modelky/public/index.html"
is not found (2: No such file or directory), client: 90.177.23.122, server:
reedink.com, request: "GET / HTTP/1.1", host: "reedink.com"
2010/11/29 23:44:44 [error] 12464#0: *30 open() "/var/app/modelky/public/favicon.ico"
failed (2: No such file or directory), client: 90.177.23.122,
server: reedink.com, request: "GET /favicon.ico HTTP/1.1", host: "reedink.com"
However, I'm using the same configuration as I use for all my other Rails 2.3.5 and Sinatra applications that works without any problems
server {
listen 80;
server_name www.reedink.com;
rewrite ^(.*) http://reedink.com$1 permanent;
}
server {
listen 80;
server_name reedink.com;
root /var/app/modelky/public;
passenger_enabled on;
}
From what I understand, Rails 3 should be rack compatible, so from the server's point of view, it's no different than any Sinatra application right?
I just built out a rail 3 box on linode this weekend. I started w/ this stackscript
http://www.linode.com/stackscripts/view/?StackScriptID=1288
and then went from there.
here's a copy of my server conf from the nginx.conf
server {
listen 80;
server_name localhost;
root /home/deploy/foo.bar.com/current/public;
passenger_enabled on;
}
i'd also try adding a static index.html file, get nginx working properly and then try and bootstrap the rails app.
Looks like your request is not hitting Rails. I would try to:
put a static index.html in /var/app/modelky/public to see if it shows up
check if the Rails app is in the given path and restart nginx
prestart Passenger on that server and see how it reacts
To prestart Passenger:
http {
server {
listen 80;
server_name www.reedink.com;
rewrite ^(.*) http://reedink.com$1 permanent;
}
server {
listen 80;
server_name reedink.com;
root /var/app/modelky/public;
passenger_enabled on;
}
passenger_pre_start http://reedink.com/;
}

Resources