rails deployment in subdomain - ruby-on-rails

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

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 ?

Properly exposing a Rails server on :80

I have a Rails server (Apache/CentOS-backed) that's accessible at mydomain.com:3000, but I'd like it to be exposed at :80 so I can access it at just mydomain.com. As best I can tell, this should be done through Apache's httpd.conf file. Mine contains the following:
<VirtualHost *:80>
ServerAdmin my-email#gmail.com
#RailsEnv development
DocumentRoot /var/www/webapps/railsSite/public
ServerName mydomain.com
ErrorLog logs/mydomain.com-error_log
CustomLog logs/mydomain.com-access_log common
<directory /var/www/webapps/railsSite/public>
AllowOverride all
Options -MultiViews
</directory>
</VirtualHost>
Am I missing anything from this block?
I'm starting my server via the standard rails server command. I looked up starting it directly to :80 via rvmsudo rails server -p 80, but I get an error saying sudo: rails: command not found. Somehow, sudo's not able to find rails?
Thanks for any help!

Hosting two rails app on single server with same IP

I have a server running a rails 3.2 application. It has thin server running on port 3000, apache(proxy) server running on 443.
Is it possible that if I try to host another rails application on the same server by creating a folder under /www and make it run on port 3002 or any other and then another apache for proxy on some other port ?
The new rails app that I have created is in Rails 4 with Ruby 2.0
Please guide.
Add another VirtualHost for port 3002
<VirtualHost *:3002>
ServerName your-server-name
DocumentRoot /www/your-second-app-public-folder-path
<Directory /www/your-second-app-public-folder-path>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
use host virtual host configuration specifying different ports for the same ip
You have multiple domains going to the same IP and also want to serve multiple ports. By defining the ports in the "NameVirtualHost" tag, you can allow this to work. If you try using <VirtualHost name:port> without the NameVirtualHost name:port or you try to use the Listen directive, your configuration will not work.
Refer Running different sites on different ports.
Server configuration
Listen 80
Listen 8080
NameVirtualHost 172.20.30.40:80
NameVirtualHost 172.20.30.40:8080
<VirtualHost 172.20.30.40:80>
ServerName www.example.com
DocumentRoot /www/domain-80
</VirtualHost>
<VirtualHost 172.20.30.40:8080>
ServerName www.example.com
DocumentRoot /www/domain-8080
</VirtualHost>

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

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>

Apache: how to config ip address without SeverName?

I want to set my own sever to run my ruby on rails project(with passenger plugin). I use Apache2 on Ubuntu11.04(sever version).
It's my first time to use Apache and I have read some documents.
All the docs ask me to set SeverName,such as Apache doc and ubuntu docs.
Unfortunately, I don't have a domain name, can I just set IP address and use IP address to access this sever?
If it's ok, how should I do?
It's the config sample given by passenger:
<VirtualHost *:80>
ServerName www.yourhost.com
DocumentRoot /somewhere/public
<Directory /somewhere/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
Thanks!
Comment out the line:
# NameVirtualHost *:80
Comment out any <VirtualHost> blocks.
Find the line:
DocumentRoot "/var/www/html" # or whatever your config uses for the overall apache document root.
Change it to your rails application's root.
DocumentRoot "/somewhere/public"
Then add your other config settings to a <Directory> block.
<Directory /somewhere/public>
AllowOverride all
Options -MultiViews
</Directory>
I haven't tested this for sure, but you should be able to get to it by only visiting the IP address. Make sure you have Passenger installed, have run passenger-install-apache2-module, and have added the appropriate module loading lines to your apache config.
/etc/apache2/httpd.conf
<VirtualHost *:80>
ServerName example.com
DocumentRoot /home/urpc-name/RailsApps/anything/public
<Directory /home/webonise/RailsApps/anything/public>
RailsEnv development
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
In server name:select ur virtual name...u can choose anything
In document root and directory,give your rails project path
Select rails environment in RailsEnv
/etc/hosts
127.0.0.1 example.com
Put server name in virtual host-127.0.0.1 is the localhost
Then just go to your browser and type example.com
Hope this helps

Resources