Apache2 multiple name-based virtual hosts on one machine with rails/rack - ruby-on-rails

Am stuck on configuring apache to serve up two different sites with Name based virtual hosts at:
http://experimental/
and
http://api.experimental/
On one machine this setup works fine, and apache reports this:
apachectl -D DUMP_VHOSTS
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:* is a NameVirtualHost
default server experimental (/etc/apache2/sites-enabled/00-nowa.conf:3)
port * namevhost experimental (/etc/apache2/sites-enabled/00-nowa.conf:3)
port * namevhost api.experimental (/etc/apache2/sites-enabled/00-nowa.conf:15)
Syntax OK
On the 2nd machine this does not work, both URLS end up pointing to the first app, it's output of the same command is which has additional : lines:
apachectl -D DUMP_VHOSTS
apache2: apr_sockaddr_info_get() failed for experimental
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[Tue May 14 15:36:08 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
[Tue May 14 15:36:08 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:* experimental (/etc/apache2/sites-enabled/00-nowa.conf:3)
*:* api.experimental (/etc/apache2/sites-enabled/00-nowa.conf:15)
Syntax OK
The vhost files for each machine are this for the broken one:
<VirtualHost *>
ServerName experimental
RailsEnv production
DocumentRoot /home/nowa/nowa_app/nowa/current/public
<Directory /home/nowa/nowa_app/nowa/current/public >
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
<VirtualHost *>
ServerName api.experimental
RackEnv production
PassengerMinInstances 2
PassengerMaxPoolSize 10
DocumentRoot /home/nowa/nowa_app/services/api_gateway/current/app
</VirtualHost>
And working:
<VirtualHost *>
ServerName experimental
RailsEnv production
DocumentRoot /home/nowa/nowa_app/nowa/current/public
<Directory /home/nowa/nowa_app/nowa/current/public >
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
<VirtualHost *>
ServerName api.experimental
RackEnv production
PassengerMinInstances 2
PassengerMaxPoolSize 10
DocumentRoot /home/nowa/nowa_app/services/nowa_api_gateway/current/app
</VirtualHost>
Why is the output of apachectl -D DUMP_VHOSTS different?
What have I missed? :C

Asked on the #httpd irc room and turns out apache was misinterpreting
<VirtualHost *>
as an IP based vhost entry, not a name based one, changing it to this fixed it:
<VirtualHost *:80>
This was because NameVirtualHost was defined like this on the broken server:
NameVirtualHost *:80
Complete working config:
<VirtualHost *:80>
ServerName experimental
RailsEnv production
DocumentRoot /home/nowa/nowa_app/nowa/current/public
<Directory /home/nowa/nowa_app/nowa/current/public >
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName api.experimental
RackEnv production
PassengerMinInstances 2
PassengerMaxPoolSize 10
DocumentRoot /home/nowa/nowa_app/services/api_gateway/current/app
</VirtualHost>

Related

rails deployment not working on port 5000

Hi I am trying to deploy a rails application on linux. I have configured everything in my app and then I have configured app.conf file in /etc/apache2/sites-available
<VirtualHost *:80>
ServerName xx.xx.xx.xx /ip of my server
ServerAlias xx.xx.xx.xx / ip of my server
ServerAdmin user#localhost
DocumentRoot /myapp/current/public
RailsEnv testing
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory "/myapp/current/public">
Allow from All
Options -MultiViews
AllowOverride all
Options FollowSymLinks
Require all granted
</Directory>
And my app is running fine when I go to xx.xx.xx.xx , but I change the port 80 to 5000 and go to xx.xx.xx.xx:5000 , app is not running.
Can anyone help me out on this. what I suppose to do ?

rails deployment in subdomain

on a dedicated server Debian 7, my default domain is www.example.org
I installed a mail server as smtp.example.org on localhost, running fine
I would like to deploy a rails app as a subdomain as : myapp.example.org
I deployed correctly the app, w Capistrano , and added a vhost :
<VirtualHost *:80>
ServerAdmin webmaster#example.org
ServerName myapp.example.org
ServerAlias myapp.example.org
DocumentRoot /var/www/rails/staging/myapp/current/public
<Directory /var/www/rails/staging/myapp/current/public>
AllowOverride All
Options -MultiViews
</Directory>
</VirtualHost>
the I enabled the site and restarted apache and tried to get http://myapp.example.org
but I always get the default site : http://www.example.org
my /etc/host is the following :
127.0.0.1 localhost smtp.example.org
localhost.localdomain localhost smtp
when I perform in the console : apache2ctl -S, I get
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
...
*:80 is a NameVirtualHost
...
port 80 namevhost myapp.example.org (/etc/apache2/sites-enabled/myapp.example.org:1)
what did I missed ?
Found the answer at :
http://shapeshed.com/developing-subdomain-rails-sites-locally/
in the vhost file , I changed :
ServerAlias *.example.com
...
Options +FollowSymlinks +SymLinksIfOwnerMatch
RackEnv staging # or development or production

Share Rails 3 Phusion Passenger Deployment Between HTTP and HTTPS

I have an apache virtual host for port 80 that hosts a rails 3 phusion passenger application. I would like some actions of the application to switch to https (port 443). What is the best way to share one instance of a phusion passenger rails application between two vhosts?
Right now, I have:
<VirtualHost *:80>
ServerName mycompany.com
ServerAlias www.mycompany.com
RackBaseURI /
DocumentRoot /home/ubuntu/mycompany/public
<Directory /home/ubuntu/mycompany/public >
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and
<VirtualHost _default_:443>
ServerName shop.mycompany.com
SSLEngine On
ProxyPass / http://localhost/
ProxyPassReverse / http://localhost/
ProxyPreserveHost On
SSLCertificateFile /etc/ssl/...
SSLCertificateKeyFile /etc/ssl/...
SSLCertificateChainFile /etc/ssl/...
</VirtualHost>
I know this is not ideal at all. There must be a better way. I do not want all requests to go through https due to the overhead.
Mike

Phusion Passenger Rails server - how to access from outside?

I switched from WEBrick to Phussion Passenger following this guide: http://developer.apple.com/library/mac/#featuredarticles/PhusionRails/index.html.
I used PassengerPane to configure it.
Now I can access my app at myapp.local, instead of localhost:3000
However, I don't know how to access it from the outside. It used to be ip:3000
My vhost.conf file looks like this:
<VirtualHost *:80>
ServerName myapp.local
DocumentRoot "/Users/martin/myapp/public"
RackEnv development
<Directory "/Users/martin/myapp/public">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
You need to add ServerAlias YOURIP:
<VirtualHost *:80>
ServerName myapp.local
ServerAlias YOURIP
DocumentRoot "/Users/martin/myapp/public"
RackEnv development
<Directory "/Users/martin/myapp/public">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
You can add as many aliases as you want (with real domain names for example).

ssl in localhost using apache and passenger

I am trying to configure SSL on my localhost using apache and phusion passenger. I am using virtualhosts.
I have the below configuration in sites-available/myapp
VirtualHost *:80
ServerName myapp
DocumentRoot /home/madhu/ror/myapp/public
RailsEnv development
Directory /home/madhu/ror/myapp/public
AllowOverride all
Options -MultiViews
Order allow,deny
allow from all
Directory
VirtualHost
VirtualHost *:443
ServerName myapp
DocumentRoot /home/madhu/ror/myapp/public
ProxyPass / http://myapp/
ProxyPassReverse / http://myapp/
ProxyPreserveHost On
RequestHeader set X_FORWARDED_PROTO 'https'
Directory /home/madhu/ror/myapp/public
AllowOverride all
Options -MultiViews
Order allow,deny
allow from all
Directory
SSLEngine On
SSLProxyEngine On
SSLCertificateFile /etc/ssl/certs/Thawte_Server_CA.pem
SSLProxyMachineCertificateFile /etc/ssl/certs/Thawte_Server_CA.pem
VirtualHost
The SSL is enabled and everything works fine. But when I go to the url https://myapp/login , it says "The requested URL /login was not found on this server". When I look at the apache logs I found out that the request is going to /var/www/login istead of /home/madhu/ror/myapp/public. This was the error log
[client 127.0.0.1] File does not exist: /var/www/login
Is there anything I am missing? Please help
Thanks.
I had to put
ServerName myapp
DocumentRoot /home/madhu/ror/myapp/public
RequestHeader set X_FORWARDED_PROTO 'https'
Directory /home/madhu/ror/myapp/public
AllowOverride all
Options -MultiViews
Order allow,deny
allow from all
Directory
SSLEngine On
SSLProxyEngine On
SSLCertificateFile /etc/ssl/certs/Thawte_Server_CA.pem
SSLProxyMachineCertificateFile /etc/ssl/certs/Thawte_Server_CA.pem
in default-ssl :P silly mistake

Resources