Deploying RoR app with Passenger: Apache shows files only from public folder - ruby-on-rails

I am a newbie in both Rails and Apache stuff. I followed tutorials to create new rails app, and tried to deploy it using Passenger.
I generated a scaffold, created+migrated database and, and it is already working on localhost:3000.
I installed apache2 and passenger, enabled mod passenger, and I can see the usual "Welcome aboard/You’re riding Ruby on Rails!" page on localhost:80 also. But I can't reach the localhost/posts page, while I can reach localhost:3000/posts. (I see "500 Internal Server Error" page, not one of the 404/422/500 pages in the public folder). I also don't see the rails image on the index page (assets/rails.png) on port #80 -everything is OK on port #3000.
I added RackEnv developer and RailsEnv developer to the virtual host file. Apache gives no error output on screen when I restart it -It reasonably gives error when I say a2dismod passenger: "Invalid command 'RackEnv'". So I assume passenger is working.
I believe somehow apache is not reading the folders except for the public folder, I tried playing around with the permissions and ownerships with no success.
Anybody has a clue?
Thanks
EDIT: I did
rake db:create RAILS_ENV=production
rake db:migrate:reset RAILS_ENV=production
and the deleted the RackEnv/RailsEnv lines from the vhost file, and restarted apache. Now I see public/500.html on localhost/posts. it is still working on localhost:3000/posts
Logs: rails log file contains only
Migrating to CreateDenemes (20120316021657)
apache error log
[Thu Mar 15 22:22:03 2012] [notice] Digest: generating secret for digest authentication ...
[Thu Mar 15 22:22:03 2012] [notice] Digest: done
[Thu Mar 15 22:22:04 2012] [notice] Apache/2.2.20 (Ubuntu) DAV/2 Phusion_Passenger/3.0.11 mod_ssl/2.2.20 OpenSSL/1.0.0e configured -- resuming normal operation
s
and other_vhosts...log is empty
V host file:
VirtualHost *:80
ServerName sencer
DocumentRoot /home/sselcuk/sencer/public
Directory /home/sselcuk/sencer/public
AllowOverride all
Options -MultiViews
/Directory
/VirtualHost

I need your log files, both Rails and apache log.
Rails log file: see: RAILS_ROOT/log/production.log
apache log file: see /var/log/apache2 ( in ubuntu)
once getting that information, we can debug for you.

Related

Passenger standalone can't start server after enabling SSL on Rails project

I have a Rails project up on an EC2 server at AWS. To deploy it, I followed this Passenger tutorial to the letter:
https://www.phusionpassenger.com/library/walkthroughs/deploy/ruby/ownserver/standalone/oss/deploy_app_main.html
Everything worked fine. Then I followed this Passenger tutorial to get SSL working:
https://www.phusionpassenger.com/library/deploy/standalone/prod_ssl.html
My Passengerfile and nginx conf file look the same as the ones in the link (with the paths replaced to point to the correct files). But now, best I can gather, the nginx server isn't starting when I use the command sudo bundle exec passenger start.
I found this on the nginx log:
May 29 18:46:20 ip-172-31-38-233 systemd[18230]: nginx.service: Failed to execute command: No such file or directory
May 29 18:46:20 ip-172-31-38-233 systemd[18230]: nginx.service: Failed at step EXEC spawning /usr/sbin/nginx: No such file or directory
Which doesn't make sense to me as nginx was working fine before the SSL certificates. Note I'm using Passenger standalone, so I'm not managing nginx myself.

I'm getting 403 error using passenger for rails in apache

I've already installed the needed tools, and followed several tutorials trying to make passenger respond.
I can access static files in public folder (public/500.html or 422.hml). Yesterday I entered through a vhost, and found some passenger errors. But some time later the hosting restarted the service, and since then I have not been able to access the rails app again.
link
link
link
These are some of the links I used to configure the server. I've also read that could be a permission issue; I've checked that, but I'm not sure it's fine.
First of all check your error log. By default, it placed at /var/log/apache2/.
If you have client denied by server configuration issue, check your site conf file at /etc/apache2/sites-available/your-site.conf. It must be in compliance with Phusion Passenger User Guide. Take a look on Require all granted.
<Directory "/home/user/folder">
Require all granted
Options FollowSymLinks
# This relaxes Apache security settings.
AllowOverride None
# MultiViews must be turned off.
Order allow,deny
Allow from all
</Directory>
OK for me this meant I was running rails 2.3 and using Phusion Passenger 5.x
Apparently 5.x doesn't work with 2.2 at all, and with 2.3 requires you to copy in a config.ru file first (so that rails will use rack for the backend).
example config.ru file for 2.3:
# Rack Dispatcher
# Require your environment file to bootstrap Rails
require File.dirname(__FILE__) + '/config/environment'
# Dispatch the request
run ActionController::Dispatcher.new
I could not figure out why no incantations seemed to work, it was like Passenger was ignoring my rails app.
In my /var/log/apache2/error.log file, I had this:
[Mon May 11 15:47:00.397891 2015] [autoindex:error] [pid 17490:tid 3058694976] [client 216.49.181.251:49248] AH01276: Cannot serve directory /home/x/y/railsapp/public/: No matching DirectoryIndex (index.html,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive, referer: https://www.google.com/
Which confused the heck out of me an apparently meant "passenger isn't running on that virtual host".
If I created a public/index.html file, apache served that fine so it wasn't a permissions issue.
I also saw this, which meant passenger was starting up ok:
[ 2015-05-11 18:23:53.9594 4964/b7415700 agents/Watchdog/Main.cpp:728 ]: All Phusion Passenger agents started!
See also https://www.phusionpassenger.com/documentation/Users%20guide%20Apache%204.0.html#_i_get_a_403_forbidden_error
So basically with passenger 5.x (in the release notes it says that rails 2.2 isn't supported, 2.3 is only supported if you create a "config.ru" file in the root of your rails app. It works with old versions of rack like rails 2.3 requires, just remove your newer rack gem and install 1.1.6 or what not, remove vendored rack gems if any. GL!
Also as a side note, this message:
[Mon May 11 18:25:10.235574 2015] [core:alert] [pid 5263:tid 3017780032] [client 127.0.0.1:56737] /home/rdp/dev/prod_flds/public/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
meant "remove your public/.htaccess file it's not needed typically by passenger"
I also got an 403 error using passenger for rails in apache on my Mac OS 10.9 (an Unix-like system).
Here's some tips:
You can check apache log directory and see the what happened.
The directory: /var/log/apache2/error_log.
Issue: Permission denied: access to / denied ( filesystem path 'path_apache_access' ) because search permissions are missing on a component of the path.
Check 'path_apache_access' by CLI: ls -ld 'path_apache_access' and use chmod +x to change the path privilege.
Also, note this: Httpd Wiki - (13) Permission Denied-.
Issue: configuration error: couldn't perform authentication. AuthType not set!.
Issue: client denied by server configuration.
Go to /etc/apache2/httpd.conf and take a look on <Directory> tag.
Check apache version by CLI: apachectl -v, if Apache < 2.4, do NOT uncomment "Require all granted".
<Directory "rails_app_directory/public">
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
# Require all granted
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>
Answer was that passenger gave me 403 because i had to set environment variable "RackEnv" on apache configuration to "development" (on my case).

Passenger Unexpected error in mod_passenger: Cannot connect to Unix socket

I just moved my rails app to a new machine. I'm using apache 2.2.3 and passenger 3.0.11. After initial load of the databases, I'm intermittently seeing an error that says the rails app failed to start. Here's what I see in my apache error log:
[Sun Mar 18 04:02:13 2012] [notice] Apache/2.2.3 (CentOS) configured -- resuming normal operations
[ pid=10788 thr=47366521234240 file=ext/apache2/Hooks.cpp:860 time=2012-03-18 08:51:10.215 ]: Unexpected error in mod_passenger: Cannot connect to Unix socket '/tmp/passenger.1.0.13044/generation-0/socket': No such file or directory (2)
Backtrace:
in 'Passenger::ApplicationPool::Client* Passenger::ApplicationPool::Client::connect(const std::string&, const std::string&, const Passenger::StaticString&)' (Client.h:438)
in 'Passenger::ApplicationPool::Client* Hooks::getApplicationPool()' (Hooks.cpp:266)
in 'Passenger::SessionPtr Hooks::getSession(const Passenger::PoolOptions&)' (Hooks.cpp:292)
in 'int Hooks::handleRequest(request_rec*)' (Hooks.cpp:561)
I've done some googling but I can only seem to find the passenger guy saying to upgrade passenger to version 3, but I'm already on version 3. I also saw somebody saying to change the logrotate script to restart apache rather than reload, which did nothing for me. Does anybody have any ideas? Here's my apache conf for passenger. I'm using an rvm version of ruby enterprise and passenger installed as a gem:
LoadModule passenger_module /usr/local/rvm/gems/ree-1.8.7-2012.02/gems/passenger-3.0.11/ext/apache2/mod_passenger.so
PassengerRoot /usr/local/rvm/gems/ree-1.8.7-2012.02/gems/passenger-3.0.11
PassengerRuby /usr/local/rvm/wrappers/ree-1.8.7-2012.02/ruby
I've also tried adding rails spawn method as conservative and adding a max pool size, with the same results. Not sure where to turn.
Do you have SELinux enabled? Run cat /selinux/enforce to find out. If it prints 1, try disabling SELinux with echo 0 > /selinux/enforce to see if that solves the problem . If that fixes the problem, you can choose to try to work around it (e.g. by setting the PassengerTempDir setting. Search for SELinux in the Passenger user guide) or leave it turned off permanently.
Recently I had the same problem. I tried:
sudo /etc/init.d/httpd restart
Stopping httpd: [FAILED]
Starting httpd: (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
[FAILED]
As last solution you always can "really" restart everything:
sudo killall httpd # <---------
sudo service httpd status
httpd is stopped
sudo service httpd start
Starting httpd: [ OK ]

Deploying a Rails Application to an LAMP server with Phusion Passenger

I just finished working on my first rails app and am ready to deploy to my VPS. I decided to try using Phusion Passenger and went through the extremely simple install process. I got all the right dependencies, so on that end things seems to be ok. Where I think my problem lies is in the routing and the apache config file.
As told I added the following at the very end of the following file: /etc/apache2/apache2.conf
LoadModule passenger_module /var/lib/gems/1.8/gems/passenger-3.0.8/ext/apache2/mod_passenger.so
PassengerRoot /var/lib/gems/1.8/gems/passenger-3.0.8
PassengerRuby /usr/bin/ruby1.8
<VirtualHost *:80>
ServerName localhost
DocumentRoot /home/bl/gfy/public
<Directory /home/bl/gfy/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
When I restart apache I get the following message:
* Restarting web server apache2 [Wed Aug 10 03:16:24 2011] [warn] module passenger_module is already loaded, skipping
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting [Wed Aug 10 03:16:26 2011] [warn] module passenger_module is already loaded, skipping
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
When I point my browser to my the IP I set up I get pointed to the sample file that comes with apache instead of to my rails app.
Any ideas would be greatly appreciated.
Thanks.
Somewhat unrelated to your problem, but still.
Both warning you see are not critical and should not affect server operations.
One means that your server hostname is not set, another just reminds you that passenger is already loaded from somewhere, probably after it stumbles upon in /etc/apache/modules.d.
All in all, you don't really want to edit /etc/apache/apache2.conf. Instead use existing structures, like /etc/apache2/sites-available etc.
Now back to your problem.
Your VirtualHost is most likely being overriden by default host.
Executing sudo a2dissite default in your shell will disable it. Assuming you don't have some exotic LAMP flavor.

Trying to run Rails App with Apache/Passenger, but getting 404s

I've installed passenger (don't know if the installation is correct) onto apache (i'm just using a development macintosh running snow leopard).
the httpd.conf file has a VirtualHost setting like this
<VirtualHost *:80>
ServerName myapp
DocumentRoot /webapps/boom/public
<Directory /webapps/boom/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
again, not sure if this is correct.
I can start up apache using apachectl start
and i can pull up the main page using this link (http://localhost).
However, when I try and go to one of my controller pages (I have a controller named blocks_controller.rb), I get a 404 error (http://localhost/blocks).
The apache error_log file shows => [Wed Jul 07 15:25:46 2010] [error] [client 127.0.0.1] File does not exist: /webapps/boom/public/blocks
I think this is something pretty simple that I'm doing wrong, but I don't know what.
Any thoughts??
Thanks!
Looks to me like Apache is not picking up the virtual host configuration so Passenger isn't in the loop. Are you sure that's all working? Apache looks a bit different in different environments so look in your OS specific locations at the Apache log files to be sure.

Resources