Rails: Vhost config for Apache and Passenger - apache

I'm trying to get a simple Rails 4 app deployed on my server which already has Apache2 and is hosting several other sites and services (ie there are several vhost configs under sites-enabled). I've had some problems doing this on my local machine as well as my test server so I'm trying first to get it working on an AWS t1.micro instance with only one vhost config. I've written a script to do most of the heavy lifting for me which is on my github at rails-apache-passenger.
I have two vhost config files in the repo and have tried to get one or the other working. The script just copies over and enables one at a time.
Using the my-ruby-app-basic or the my-ruby-app vhost config I navigate to http://54.xxx.xxx.xxx/my-ruby-app/ but all I see is "The page you were looking for doesn't exist. You may have mistyped the address or the page may have moved." When I go to ttp://54.xxx.xxx.xxx/ I just get the default apache2 page ("It works!").
My /var/www/my-ruby-app/log/production.log shows
I, [2014-01-24T10:47:36.900542 #9612] INFO -- : Started GET "/my-ruby-app" for 80.81.17.94 at 2014-01-24 10:47:36 +0000
F, [2014-01-24T10:47:36.902169 #9612] FATAL -- :
ActionController::RoutingError (No route matches [GET] "/my-ruby-app"):
So clearly I need to modify my routes.rb file, but what am I supposed to change? As you can see from the script in the git repo, it's just the default routes.rb from rails new. I just want to see the default rails app landing page at this point so I'm not sure what to do to the routes.rb file.
Here are the vhost configs
my-ruby-app-basic
#This is the config suggested by the passenger module after it finishes compiling, modified for 'my-ruby-app'
<VirtualHost *:80>
ServerName www.my-ruby-app-host.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/my-ruby-app/public
<Directory /var/www/my-ruby-app/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
my-ruby-app
#Based on Apache section of Passenger documents
<VirtualHost *:80>
ServerName www.my-ruby-app-host.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/
<Directory /var/www/>
Allow from all
</Directory>
Alias /my-ruby-app /var/www/my-ruby-app/public
<Location /my-ruby-app>
PassengerBaseURI /my-ruby-app
PassengerAppRoot /var/www/my-ruby-app
</Location>
<Directory /var/www/my-ruby-app/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
</Directory>
</VirtualHost>
Using Apache and Passenger is a short term solution but I want to know how to do it in any case (The long term view is that I want to maintain compatibility with Jruby and just run our app through Tomcat or Glassfish, which will no doubt be another Apache config debacle ;-) )

Related

VirtualBox Ubuntu 16.04 apache2 vhost jumping to https or not showing the page

I am trying to set up some vhosts on a Virtual Box with Ubuntu 16.04 Apache2 PHP 7.0 to start moving the code to PHP7.
I have moved the v-host file from the older VBox which looked like this
<VirtualHost 192.168.2.174:80>
ServerName admin.ubuntu16.de
ServerAlias admin.ubuntu16.de
ServerAdmin email#company.de
DocumentRoot /home/www/public_html/workspace/admin
php_value auto_prepend_file '/home/www/public_html/workspace/admin/administration/conf/register_globals.php'
<Directory /home/www/public_html/workspace/admin>
Options Indexes FollowSymLinks MultiViews ExecCGI
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
But it kept on trying to load the page with https or saying that there is no access to site root folder
These settings work perfectly on Ubuntu 14 Virtuall Box with apache2 and PHP 5.5.something
So I followed the tutorial and changed it to simply
<VirtualHost 192.168.2.174:80>
ServerName admin.ubuntu16.de
ServerAlias admin.ubuntu16.de
ServerAdmin email#company.de
DocumentRoot /home/www/public_html/workspace/admin
</VirtualHost>
But now it just jumps straight to https mode
I obviously ran a2ensite
I also switched off the default site by running "a2dissite 000-default.conf"
I also enable modules to do with proxying and a bunch of others while getting appache to actuallly start :-)
Any ideas on things I might off missed are greatly appreciated.
Just a little edit:
All the files for the sites are situated on the main Windows machine and are imported through /media/sf-workspace
The symbolic link is then created as /home/www/public_html/workspace
I would first eliminate the symbolic links and just make a copy of all the files inside the virtual box to remove that variable.
Apache can be screwy with symlinks.

vhosts dont appear to be working on OS X Mavericks Apache installation

I am trying to set up the Apache server which comes with OS X Mavericks with vhosts so that a domain name resolves to my user level document webroot. I have followed this tutorial which guided me through setting up the apache server with php:
http://coolestguidesontheplanet.com/get-apache-mysql-php-phpmyadmin-working-osx-10-9-mavericks/
as well as this one which guided me through setting up the vhosts:
http://coolestguidesontheplanet.com/set-virtual-hosts-apache-mac-osx-10-9-mavericks-osx-10-8-mountain-lion/
Following these tutorials, if I type localhost in my browser it correctly resolves to the system level root (/Library/WebServer/Documents/ folder). If I use localhost/~myusername it correctly resolves to my user level root (/users/myusername/Sites/).
However, whenever I navigate to my domain, I get redirected to the system level root rather than my user level root.
My vhosts file reads as follows:
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents/
</VirtualHost>
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot "/Users/myusername/Sites/mydomain"
<Directory "/Users/myusername/Sites/mydomain">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Any ideas?
Have you enabled Virtualhosts?
NameVirtualHost *:80
And included your vhosts directory
Include <path>/vhosts/*
On a Macbook, you may need to include /private/ at the beginning of any absolute path, so that Apache can read it correctly off the file system.
For others who have the same problem...
It was frustratingly simple - I had missed the "" around the localhost directory.
How annoying!
Try starting apache manually with the -S option to see what the problem might be:
/usr/sbin/httpd -S

redmine and mod_vhost_dbd

I've problem to run redmine with vhost_dbd_module from apache. Redmine was installed under /var/www/redmine/ directory. My apache config look:
<VirtualHost *:80>
ServerName HOSTNAME
DocumentRoot "/var/www/" # THIS IS NOT WORKING
# DocumentRoot "/var/www/redmine/public" # THIS WORKS WITH REDMINE
<Directory />
Options FollowSymLinks -MultiViews -Indexes
AllowOverride All
</Directory>
DBDriver mysql
DBDParams host=localhost,user=test,pass=test,dbname=test
DBDocRoot "SELECT document_root FROM vhosts WHERE server_name = %s" HOSTNAME
</VirtualHost>
Field document_root from database return '/var/www/redmain/public' - so it should works. It works for php projects where index file is under '/var/www/project/public'. Besides the page return 404 because in /var/www/redmain/public there is no index file. I want universal config
Any suggestions?
Best regards, Peter
Not havng a index.html is ok :) Check your config/routes.rb.
If rails service is running then your redmine rails check your routes.rb and deliver the default page there (view).
Passenger as an apache module is not compatible with about all modules used to define "dynamic" document roots (including mod_vhost_dbd). For passenger, you have to statically configure your apps in the Apache configuration.
Generally, you will have a hard time emulating your PHP setup with any Ruby app server, as they expect to be started once and run continuously, unlike PHP "apps" which act as scripts resolved and started new for each request. You should rethink your setup for persistent application server processes.
I created .htaccess with content below and it working :)
RailsBaseURI /
PassengerAppRoot /var/www/redmine

get 404 with passenger and rails

I'm trying to run a rails app on a shared hoster.
I create the app in the directory /home/rails_projects/jens_blog and the document root is /home/www/jens_blog.
In the /home/www/jens_blog dir is a symlink public -> /home/rails_projects/jens_blog/public/
I created a scaffold posts. But when i run the mydomain/ or mydomain/posts in the browser I get always an 404 error.
File does not exist: /home/www/jens_blog/public/posts
<VirtualHost ip.port>
ServerName www.mydomain.de
ServerAdmin webmaster#www.mydomain.de
DocumentRoot /home/www/jens_blog/public
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.7
PassengerRuby /usr/bin/ruby
PassengerDefaultUser myuser
PassengerAnalyticsLogUser myuser
CustomLog /home/log/access_log mesos2
<Directory "/home/www/jens_blog/public">
Allow from all
Options -MultiViews
Options FollowSymLinks
</Directory>
</VirtualHost>
if I put a index.php file into the /home/rails_projects/jens_blog/public/ dir the file content will be show.
Can anybody help me?? I am desperated.
I have only a shared web hosting.
Update: I added "PassengerResolveSymlinksInDocumentRoot on" to the apache config. But now I get Exception LoadError in PhusionPassenger::Rack::ApplicationSpawner (no such file to load -- bundler)
:-((
Cheers
Jens
My question was quite similar to yours Deployed rails site on ec2 using capistrano, but it doesn't show up on the browser, here is the site -> http://passionate4.net/
I would say place your site in this directory /var/www/myapp/public.
Use these settings.
ServerName www.passionate4.net
DocumentRoot /var/www/capi_app/current/public
RailsEnv production
Allow from all
Options -MultiViews
I have written couple of blogs on how to successfully deploy the site on Ubuntu. I believe you problem is quite similar to mine. http://recipe4developer.wordpress.com/

Magento not accessible since tried to move to multi website setup. Apache issue?

I wish I had never seen this article:
http://www.magentocommerce.com/knowledge-base/entry/tutorial-multi-site-multi-domain-setup
I have Apache 2.2 installed on my XP machine and until a while ago I had a Magento site that I could test the development of a custom module on. I decided that I wanted to have multiple websites and multiple stores so that I could test that my modules configuration variables set at the different scopes (global, website, and store) were working as expected.
So I followed the instructions in the above Magento article. I created a website and gave it a name of “paulsplace.com”. I created a couple of Stores under that website. I then went to System/Configuration/General/Web and, with the scope set to paulsplace.com, I set the unsecured and secured URLs to http://paulsplace.com/ and https://paulsplace.com/ and hit Save Config - what a mistake!!
I got a 404 error. And now I can’t get to my magento front end or back end.
I tried a couple of things:
I added these lines to my hosts lookup file:
127.0.0.1 paulsplace.com
127.0.0.1 www.paulsplace.com
I then uncommented this line in my httpd,conf file:
Include conf/extra/httpd-hosts.conf
and added the following to the conf/extra/httpd-hosts.conf file:
<VirtualHost *:80>
ServerAdmin me#myemail.com
DocumentRoot "C:/Applications/Apache Software Foundation/Apache2.2/htdocs"
ServerName paulsplace.com
ErrorLog "logs/paulsplace.com-error.log"
CustomLog "logs/paulsplace.com-access.log" common
</VirtualHost>
and restarted Apache.
If I browse to “http://www.paulsplace.com” I now get a page that just says “It works!”. Same for “http://paulsplace.com” and “http://www.paulsplace.com/magento/index.php”.
I tried a few more things - I added this line to httpd.conf:
AccessFileName htaccess
(I did this because Windows Explorer didn’t let me create a file starting with a dot; I could do it from the command prompt, but I believe what I have done should be ok).
I changed AllowOverride to All from None:
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Deny from all
</Directory>
<Directory "C:/Applications/Apache Software Foundation/Apache2.2/htdocs">
AllowOverride All
</Directory>
and in C:\Applications\Apache Software Foundation\Apache2.2\htdocs\htaccess (a file that I created), I entered:
SetEnvIf Host www\.paulsplace\.com MAGE_RUN_CODE=pws1
SetEnvIf Host www\.paulsplace\.com MAGE_RUN_TYPE=website
SetEnvIf Host ^paulsplace\.com MAGE_RUN_CODE=pws1
SetEnvIf Host ^paulsplace\.com MAGE_RUN_TYPE=website
(pws was the value I used for the “Code” when creating my store).
Please tell me how I can put this right. I feel like I’m taking one step forward and three backward at the moment.
Any help really would be greatly appreciated.
<VirtualHost *:80>
ServerAdmin me#myemail.com
DocumentRoot "Change this to point at your magento install"
ServerName paulsplace.com
ErrorLog "logs/paulsplace.com-error.log"
CustomLog "logs/paulsplace.com-access.log" common
SetEnv MAGE_RUN_TYPE website
SetEnv MAGE_RUN_CODE pws1
</VirtualHost>
If changing anything in System Configuration borks your system, you can always clear out the bad values in the database directly, and clear your Magento cache. Do a
select * from core_config_data where value LIKE '%paulsplace.com%'
This will give you the two rows that were added when you clicked save. Remove the rows. Next, clear out all the files in
var/cache/*
to clear your cache. Then restore your Apache config to what it was before you started monkeying around. This should restore your site back to its previous state, and you can continue to experiment with things.