I have installed mod_passenger (passenger-install-apache2-module) and have the following in my Apache configuration:
LoadModule passenger_module /var/www/html/vendor/bundle/ruby/2.2.0/gems/passenger-5.0.24/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /var/www/html/vendor/bundle/ruby/2.2.0/gems/passenger-5.0.24
PassengerDefaultRuby /usr/local/rvm/wrappers/ruby-2.2.2/ruby
</IfModule>
RackEnv production
<VirtualHost *:80>
ServerName domain.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/html/public
<Directory /var/www/html/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
My Rails website is working however some URLs that end in .php or .txt do not get processed by Passenger resulting in a generic 404 page instead of the nicely formatted 404 page on my Rails site.
How can I route all file extensions to Passenger/Rails?
Or how can I make URLs that end in .php actually be processed by PHP.
Related
I am deploying a ruby-on-rails application.
I have configured apache and passenger and the http server is listening on port 80.
When I try to access the home page using the browser, I simply get a list of files and directories instead of the home page.
Following are snippets from the apache config.
/etc/apache2/apache2.conf
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>
/etc/apache2/httpd.conf
LoadModule passenger_module /home/user1/.rvm/gems/ruby-2.3.0/gems/passenger-5.0.27/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/user1/.rvm/gems/ruby-2.3.0/gems/passenger-5.0.27
PassengerDefaultRuby /home/user1/.rvm/gems/ruby-2.3.0/wrappers/ruby
</IfModule>
/etc/apache2/sites-available/ubuntuvm-4.conf
<VirtualHost *:80>
ServerAdmin admin#ubuntuvm-4.com
ServerName ubuntuvm-4
ServerAlias www.ubuntuvm-4.com
DocumentRoot /home/user1/www/myapp/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What is going wrong?
Could it be that I am trying to access the page via the ip address
http://192.168.0.12?
If you want me to put any other config, please shout.
try to copy the content of the file /etc/apache2/sites-available/ubuntuvm-4.conf
to /etc/apache2/sites-enabled/ubuntuvm-4.conf
cp /etc/apache2/sites-available/ubuntuvm-4.conf /etc/apache2/sites-enabled/ubuntuvm-4.conf
You need to create your config like this
<VirtualHost *:80>
ServerName ubuntuvm-4
<Location /home/user1/www/myapp/public>
PassengerBaseURI /
PassengerAppRoot /home/user1/www/myapp
</Location>
DocumentRoot /home/user1/www/myapp/public
<Directory /home/user1/www/myapp/public>
AllowOverride all
RailsEnv production
# MultiViews must be turned off.
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
Require all granted
</Directory>
</VirtualHost>
I had the same problem trying to deploy a 4.2.1 Rails app on Ubuntu 12.04 using Ruby 2.3.2 (RVM because .deb packaged version is damn too old !!) Apache 2.2 and Passenger 5.0.4 (.deb).
Well, after wasting days to try to figure out why passenger wouldn't start (I did this a thousand times, it always worked), I realized it was only because Passenger couldn't print its logs anywhere. So, if you already tried everything you read on forums, just try to add a path to a log file in your apache configuration :
PassengerLogFile /var/log/passenger.log
and it worked like magic. Hope this helps.
This is driving me nuts.
I have 2 different rails app running on the same redhat server. The web server is apache and app server is passenger 5.0
App1 - rails 3.0.2 and ruby 1.9.3
App2- rails 2.0.3 & ruby 1.8.7
App1 works fine and this is the configuration:
<VirtualHost *:8081>
ServerName server-xyz
RailsEnv test
DocumentRoot /webapps/test/app1/current/public
<Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Now when I run app2 it takes me to the default apache page and gives me the following error:
Directory index forbidden by Options directive:
/webapps/test/app2/current/public/
This is the virtual host for app2:
<VirtualHost *:8081>
ServerName server-xyz
RailsEnv test
DocumentRoot /webapps/test/app2/current/public
<Directory />
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
This is the common passgenger configuration:
LoadModule passenger_module /opt/ruby-1.9.3/lib/ruby/gems/1.9.1/gems/passenger-5.0.8/buildout/apache2/mod_passenger.so
PassengerRoot /opt/ruby-1.9.3/lib/ruby/gems/1.9.1/gems/passenger-5.0.8
PassengerDefaultRuby /opt/ree-1.8.7/bin/ruby_with_env
PassengerLogLevel 1
PassengerMaxPoolSize 10
Anyone has any ideas why it works for ruby.1.9.3 app and not for ruby 1.8.7?
I tried following similar threads but couldnt get it to work.
EDIT: I gave 'apache' write permissions to that path. Didn't seem to help.
EDIT 2: I found the following .htaccess configuration under public:
/webapps/test/app2/releases/20150622171404/public/.htaccess
# General Apache options
AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI
RewriteEngine On
# If your Rails application is accessed via an Alias directive,
# then you MUST also set the RewriteBase in this htaccess file.
#
# Example:
# Alias /myrailsapp /path/to/myrailsapp/public
# RewriteBase /myrailsapp
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
If you are on passenger 5 and running ruby 1.8.7 & rails 2 app, you need to add a config.ru to the root of your application:
# config.ru
# Require your environment file to bootstrap Rails
require ::File.dirname(__FILE__) + '/config/environment'
# Serve static assets from RAILS_ROOT/public directory
# use Rails::Rack::Static
# Dispatch the request
run ActionController::Dispatcher.new
For the second application configuration, update it with:
<VirtualHost *:8081>
ServerName server-xyz
RailsEnv test
DocumentRoot /webapps/test/app2/current/public
<Directory />
Options FollowSymLinks Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and check the filesystem that you don't have a .htaccess file with custom configuration for the Indexes option either on the app directory or on a upper directory
If you are using ruby 1.8.7 and Rails 2.X. I found the easiest option was to downgrade from passenger 5 to passenger 4.0.59.
I have main Rails app working on system Ruby and Passanger. Following virtual host works just fine:
<VirtualHost x.x.x.x:80>
ServerName domain.com
DocumentRoot /home/john/apps/main_app/public
PassengerRoot /var/lib/gems/1.9.1/gems/passenger-4.0.29
PassengerRuby /usr/bin/ruby
<Directory /home/deploy/apps/main_app/public>
PassengerEnabled On
AllowOverride All
Require all granted
Options -MultiViews
</Directory>
</VirtualHost>
Now I want to add second virtual host for my second app working on different Ruby/Passanger versions and different domain but on same machine:
<VirtualHost x.x.x.x:80>
ServerName domain2.com
DocumentRoot /home/deploy/apps/app/public
PassengerRoot /home/deploy/.rvm/gems/ruby-2.1.5#app/gems/passenger-4.0.59
PassengerRuby /home/deploy/.rvm/rubies/ruby-2.1.5/bin/ruby
<Directory /home/deploy/apps/app/public>
PassengerEnabled On
AllowOverride All
Require all granted
Options -MultiViews
</Directory>
</VirtualHost>
After enabling second VirtualHost the first one (main app) is not working anymore. In browser I have 403 error. Same situation for second app.
Error log from main application:
[Sun Feb 15 13:29:08.596451 2015] [autoindex:error] [pid 53380] [client x.x.x.x] AH01276: Cannot serve directory /home/john/apps/main_app/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: x
After disabling second app first one is working. How can I make to work both apps in the same time?
The configurations are incorrect. The two virtual hosts are using two different Passenger versions, and loading two different Ruby versions.
<VirtualHost x.x.x.x:80>
PassengerRoot /var/lib/gems/1.9.1/gems/passenger-4.0.29
PassengerRuby /usr/bin/ruby
</VirtualHost>
vs
<VirtualHost x.x.x.x:80>
PassengerRoot /home/deploy/.rvm/gems/ruby-2.1.5#app/gems/passenger-4.0.59
PassengerRuby /home/deploy/.rvm/rubies/ruby-2.1.5/bin/ruby
</VirtualHost>
I've been struggling with this for hours. It's the first time that I try to establish a server.
I have rails, passenger and apache installed.
In the httpd.conf here is what I wrote:
ServerRoot "/etc/httpd"
# Here I wrote the IP address, since I still did not manage the DNS
Listen ##.##.##.94:80
ServerAdmin root#localhost
ServerName ##.##.##.94:80 # Do I need this?
<Directory />
AllowOverride none
Require all denied
Options Indexes FollowSymLinks Includes ExecCGI
</Directory>
<Directory "/var/www">
AllowOverride None
# Allow open access:
Require all granted
</Directory>
LoadModule passenger_module /usr/local/rvm/gems/ruby-1.9.3-p551/gems/passenger-4.0.59/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/rvm/gems/ruby-1.9.3-p551/gems/passenger-4.0.59
PassengerDefaultRuby /usr/local/rvm/gems/ruby-1.9.3-p551/wrappers/ruby
</IfModule>
<VirtualHost *:80>
ServerName ##.##.##.##
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/blah_blah/public_html/public
<Directory /var/www/blah_blah/public_html>
# 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
</Directory>
</VirtualHost>
The last section was produced by passenger (I did not! copy it from the instructions :-) ).
When I go to the IP address I get an error that the page was not found.
I have rails running with "rails s". Before that I reloaded the server and restarted it for the config file to take effect.
Also, I granted apache user permission to the www folder.
What is the problem?
I even tried to put an index.html file in the public folder of rail and tried to go there, but failed.
BTW - when I do it from the console:
wget http://0.0.0.0:3000
I get a 200 response which means that it is OK.
Where is the fault?
I think you should change the port:
<VirtualHost *:3000>
Because when you run rails s it run on port 3000.
My requirement is to access http://myhost/ for my ROR project and access phpmyadmin and bugzilla using http://myhost/phpmyadmin/ and http://myhost/bugzilla/.
I wonder how to configure my VirtualHost and DocumentRoot, thanks for your comments!
Content of my /etc/httpd/conf/httpd.conf
LoadModule passenger_module /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.14/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.9.1/gems/passenger-3.0.14
PassengerRuby /usr/bin/ruby
.....
.....
<VirtualHost *:80>
ServerName myhost
DocumentRoot /var/www/html/myProject/public
RailsEnv development
<Directory /var/www/html/myProject/public>
AllowOverride All
Options -MultiViews
</Directory>
</VirtualHost>
After digging the Passenger documents, I find there is a simple way to do so
<VirtualHost *:80>
ServerName myhost
DocumentRoot /var/www/html/myProject/public
RailsEnv development
<Directory /var/www/html/myProject/public>
AllowOverride All
Options -MultiViews
</Directory>
Alias /blog /var/www/html/phpmyadmin
<Location /phpmyadmin>
PassengerEnabled off
</Location>
</VirtualHost>
This will enforce Passenger to skip request under path /phpmyadmin
The easiest way, and with least amount of headaches would to just create subdomains for phpmyadmin and bugzilla. Then, just create a new virutalhost for each subdomain.
But, if your setup is necessary this seems like I possible solution.
http://macdiggs.com/2007/06/29/using-php-inside-rails-structure-on-apache/