Virtual host with Passenger - ruby-on-rails

Rails app already works correctly on mydomain.com with Apache+Passenger. In addition, I'm going to deploy non-Rails app(wordpress) on blog.mydomain.com. So I modified httpd.conf like
PassengerEnabled off
<VirtualHost *:80>
ServerName mydomain.com
DocumentRoot /var/www/railsapp/public
PassengerEnabled on
</VirtualHost>
<VirtualHost *:80>
ServerName blog.mydomain.com
DocumentRoot /var/www/blog
</VirtualHost>
But this doesn't work. blog.mydomain.com also shows Rails app. How can I divide them?

Try adding this to the top of the conf file:
NameVirtualHost *:80
You might also try swapping the order so the more specific one is first, but look at the section called 'Using the ServerPath Directive' on this page. It indicates that with older http/1.0 clients, you may not have enough information to route it correctly.

Related

Setup and configure Zend Skeleton Application

I'm new to Zend Framework 2 and have installed the Skeleton Application manually. My application is kept in "D:\xampp\htdocs\zf2". I've created a virtual host but when I point it to the public folder in D:\xampp\htdocs\zf2\public" it gives the error object not found. However, if I have the option other option like "D:\xampp\htdocs\zf2" then it works. I've also tried putting index.php at the end and that also works but it gives output like this.
I've set the virtual host in httpd-vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "D:\xampp\htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
ServerName zf2
DocumentRoot "D:/xampp/htdocs/zf2/public"
<Directory "D:/xampp/htdocs/zf2/public">
#DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and in C:/Windows/System32/Drivers/etc/hosts file I added the line 127.0.0.1 zf2
Can any one help me on this?

How to change the URL from "localhost" to something else, on a local system using wampserver?

On a Windows machine, there's a system running on the local wampserver, but while the application is running on localhost, the URL says otherwise.
While I would expect the URL to be like this based on the directory structure:
http://localhost/pro/include/db_report.php
The developer has managed to do this:
http://ap-mispro/pro/include/db_report.php
So instead of localhost, the URL says ap-mispro.
And both URLs work fine.
How is the second URL made? I tried checking out the wampmanager.ini and wampmanager.tpl but maybe I didn't know what to look for?
WINDOWS + WAMP solution
Step 1
Go to C:\wamp\bin\apache\Apache2.2.17\conf\ open httpd.conf file and change #Include conf/extra/httpd-vhosts.conf to Include conf/extra/httpd-vhosts.conf i.e. uncomment the line so that it can includes the virtual hosts file.
Step 2
Go to C:\wamp\bin\apache\Apache2.2.17\conf\extra and open httpd-vhosts.conf file and add the following code
<VirtualHost myWebsite.local>
DocumentRoot "C:/wamp/www/myWebsite/"
ServerName myWebsite.local
ServerAlias myWebsite.local
<Directory "C:/wamp/www/myWebsite/">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
change myWebsite.local and C:/wamp/www/myWebsite/ as per your requirements.
Step 3
Open hosts file in C:/Windows/System32/drivers/etc/ and add the following line ( Don't delete anything )
127.0.0.1 myWebsite.local
change myWebsite.local as per your name requirements
Step 4
restart your server. That's it
WINDOWS + XAMPP solution
Same steps as that of WAMP just change the paths according to XAMPP which corresponds to path in WAMP
Copy the hosts file and add 127.0.0.1 and name which you want to show or run at the browser link. For example:
127.0.0.1 abc
Then run abc/ as a local host in the browser.
They are probably using a virtual host (http://www.keanei.com/2011/07/14/creating-virtual-hosts-with-wamp/)
You can go into your Apache configuration file (httpd.conf) or your virtual host configuration file (recommended) and add something like:
<VirtualHost *:80>
DocumentRoot /www/ap-mispro
ServerName ap-mispro
# Other directives here
</VirtualHost>
And when you call up http://ap-mispro/ you would see whatever is in C:/wamp/www/ap-mispro (assuming default directory structure). The ServerName and DocumentRoot do no have to have the same name at all. Other factors needed to make this work:
You have to make sure httpd-vhosts.conf is included by httpd.conf for your changes in that file to take effect.
When you make changes to either file, you have to restart Apache to see your changes.
You have to change your hosts file
http://en.wikipedia.org/wiki/Hosts_(file) for your computer to know
where to go when you type http://ap-mispro into your browser. This
change to your hosts file will only apply to your computer - not
that it sounds like you are trying from anyone else's.
There are plenty more things to know about virtual hosts but this should get you started.
please refer http://complete-concrete-concise.com/web-tools/how-to-change-localhost-to-a-domain-name
this is best solution ever
for new version of Wamp
<VirtualHost *:80>
ServerName domain.local
DocumentRoot C:/wamp/www/domain/
<Directory "C:/wamp/www/domain/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
After another hour or two I can actually answer my own question.
Someone on another forum mentioned that you need to keep a mention of plain ol' localhost in the httpd-vhost.conf file, so here's what I ended up with in there:
ServerName localhost
DocumentRoot "c:/wamp/www/"
DocumentRoot "C:/wamp/www/pocket/"
ServerName pocket.clickng.com
ServerAlias pocket.clickng.com
ErrorLog "logs/pocket.clickng.com-error.log"
CustomLog "logs/pocket.clickng.com-access.log" common
<Directory "C:/wamp/www/pocket/">
Options Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Exit WAMP, restart - good to go. Hope this helps someone else :)
go to C:\Windows\System32\drivers\etc and open hosts file and add
this
127.0.0.1 example.com
127.0.0.1 www.example.com
then go to C:\xampp\apache\conf\extra open httpd-ajp.conf file and add
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/pojectroot"
ServerName example.com
ServerAlias www.example.com
<Directory "C:/xampp/htdocs/projectroot">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
WINDOWS + MAMP solution
Step 1
Go to S:\MAMPenter code here
\bin\apache\conf\ open httpd.conf file and change
#Include conf/extra/httpd-vhosts.conf
to
Include conf/extra/httpd-vhosts.conf i.e. uncomment the line so that it can includes the virtual hosts file.
Step 2
Go to S:\MAMP\bin\apache\conf\extra and open httpd-vhosts.conf file and add the following code
<VirtualHost myWebsite.local>
DocumentRoot "S:\MAMP\htdocs/myWebsite/"
ServerName myWebsite.local
ServerAlias myWebsite.local
<Directory "S:\MAMP\htdocsmyWebsite/">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
change myWebsite.local and S:\MAMP\htdocs/myWebsite/ as per your requirements.
Step 3
Open hosts file in C:/Windows/System32/drivers/etc/ and add the following line ( Don't delete anything )
127.0.0.1 myWebsite.local
change myWebsite.local as per your name requirements
Step 4
restart your server. That's it
This method will work for xamp/wamp/lamp
1st go to your server directory, for example, C:\xamp
2nd go to apache/conf/extra and open httpd-vhosts.conf
3rd add following code to this file
<VirtualHost myWebsite.local>
DocumentRoot "C:/wamp/www/php-bugs/"
ServerName php-bugs.local
ServerAlias php-bugs.local
<Directory "C:/wamp/www/php-bugs/">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
For DocumentRoot and Directory add your local directory
For ServerName and ServerAlias give your server a name
Finally go to C:/Windows/System32/drivers/etc and open hosts file
add 127.0.0.1 php-bugs.local and nothing else
For the finishing touch restart your server
For Multile local domain add another section of code into httpd-vhosts.conf
<VirtualHost myWebsite.local>
DocumentRoot "C:/wamp/www/php-bugs2/"
ServerName php-bugs.local2
ServerAlias php-bugs.local2
<Directory "C:/wamp/www/php-bugs2/">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and add your host into host file 127.0.0.1 php-bugs.local2

Rails 3 Deploy: Multiple rails apps single domain error: No such file or directory - config/environment.rb

Yesterday, I bought a server on Linode. I setup Apache, RVM, Rails, MySQL and have got a single rails app hosted on a domain, following a nice guide from http://library.linode.com/frameworks/ruby-on-rails-apache/ubuntu-10.04-lucid. It also explains how to put multiple rails apps on the same domain, however when I try, I get an error when I access my domain our-portal.com/adm :
No such file or directory - config/environment.rb
Application root: /srv/www/our-portal.com/public_html
Somethings wrong here... anyone have any ideas? I am able to host a single app just fine, but not multiple... Here is my Virtual Host settings
<VirtualHost *:80>
ServerAdmin webmaster#our-portal.com
ServerName our-portal.com
ServerAlias www.our-portal.com
DocumentRoot /srv/www/our-portal.com/public_html/
RailsBaseURI /adm
RailsBaseURI /matrix
ErrorLog /srv/www/our-portal.com/logs/error.log
CustomLog /srv/www/our-portal.com/logs/access.log combined
</VirtualHost>
My applications path is in /srv/www/our-portal.com/adm/ and I linked using
ln -s /srv/www/our-portal.com/adm/public/ /srv/www/our-portal.com/public_html/adm/
ln -s /srv/www/our-portal.com/matrix/public/ /srv/www/our-portal.com/public_html/matrix/
Try by setting the DocumentRoot to the public folder of your application:
DocumentRoot /srv/www/our-portal.org/app/public
I got it working, these are the changes I made.
<VirtualHost *:80>
ServerAdmin webmaster#our-portal.com
ServerName our-portal.com
ServerAlias www.our-portal.com
DocumentRoot /srv/www/our-portal.com/public_html
<Directory /srv/www/our-portal.com/public_html>
Allow from all
</Directory>
RailsBaseURI /adm
RailsBaseURI /matrix
<Directory /srv/www/our-portal.com/public_html/adm>
Options -MultiViews
</Directory>
<Directory /srv/www/our-portal.com/public_html/matrix>
Options -MultiViews
</Directory>
ErrorLog /srv/www/our-portal.com/logs/error.log
CustomLog /srv/www/our-portal.com/logs/access.log combined
</VirtualHost>
I also believe my links were not created correctly. It helped to type
ln -s
and double-click tab (without executing the command) to look at the correct way Unix handles the path for this function. My links looked like this
ln -s /srv/www/our-portal.com/adm/public/ our-portal.com/public_html/adm
ln -s /srv/www/our-portal.com/sitedb-pro/public/ our-portal.com/public_html/matrix
Notice the difference from my old links. Using double-click tab I was able to reference these folders correctly.

How do you use apache to route different subdomains to different ports / servers?

On my dev machine, I want to be able to have an SSL server, and a non-SSL server (both running off the same code... but running both servers is the easy part.)
For my regular server: I want it to be sub1.mydomain.com
so, I've modified my VirtualHost such that instead of saying
mydomain.com
*.mydomain.com,
it says
sub1.mydomain.com
*.sub1.mydomain.com
and then for the SSL server, I just said
sub2.mydomain.com
*.sub2.mydomain.com
except, whenever I got to a sub2.mydomain url, the server attached to sub1 processes the request.
What am I doing wrong here?
I'm using ruby on rails, and apache.
EDIT: added the actual virtual hosts
<VirtualHost *:80>
DocumentRoot "/Users/me/projects/myproject/public"
ServerName reg.mydomain.com
#ServerAlias *.reg.mydomain.com
ProxyPass / http://localhost:3001/
ProxyPassReverse / http://localhost:3001
</VirtualHost>
<VirtualHost *:443>
SSLEngine on
SSLProxyEngine On
RequestHeader set Front-End-Https "On"
CacheDisable *
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
DocumentRoot "/Users/me/projects/myproject/public"
ServerName ssl.mydomain.com
#ServerAlias *.ssl.mydomain.com
SSLCertificateKeyFile "/private/etc/apache2/certs/server.key"
SSLCertificateFile "/private/etc/apache2/certs/server.crt"
ProxyPass / https://localhost:3002/
ProxyPassReverse / https://localhost:3002
ProxyPreserveHost on
</VirtualHost>
It sounds like you're trying to do named virtual hosts?
http://httpd.apache.org/docs/2.2/vhosts/name-based.html
Assuming that rails isn't doing anything too funky, you can try having a virtual host that looks like this:
NameVirtualHost *
<VirtualHost *>
ServerName sub1.mydomain.com
DocumentRoot /var/www/sub1 or point this to the server instead.
</VirtualHost>
<VirtualHost *>
ServerName sub2.mydomain.com
DocumentRoot /var/www/sub2 or point this to the server instead.
</VirtualHost>

Passenger: RailsBaseURI case sensitive?

I used Passenger to deploy a RoR app to a sub URI on my domain. The problem I'm facing is that the sub URI seems to be case sensitive. Navigating to http://mydomain.com/RailsApp resolves fine. However, if I go to http://mydomain.com/railsapp, http://mydomain.com/railsApp, or any other variation, I get a 404 error. How can these requests using different casings get resolved correctly?
Here is my Apache configuration file:
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /www/mydomain/public
<Directory "/www/mydomain/public">
RailsEnv "production"
Order allow,deny
Allow from all
</Directory>
RailsBaseURI /RailsApp
<Directory "/www/RailsApp/public">
RailsEnv "development"
Options -MultiViews
</Directory>
</VirtualHost>
Any help is much appreciated. Thanks!
You could look into using mod_rewrite and matching it case insensitive there.
Some links to get you started :)
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html
http://httpd.apache.org/docs/2.2/misc/rewriteguide.html
Thanks ba for pointing me in the right direction.
I did some research and found the mod_speling module. This not only makes the URL case-insensitive but also checks for spelling errors.
To enable mod_speling:
sudo /usr/sbin/a2enmod speling
sudo /etc/init.d/apache2 force-reload
sudo /etc/init.d/apache2 restart
To use mod_speling, include the directive CheckSpelling on in your virtual host section:
<VirtualHost *:80>
CheckSpelling on
...
</VirtualHost>

Resources