Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using cPanel Apache 2 on my VPS server to host PHP / MySQL websites on port 80.

So let's say we have myphp.com which just works fine.

Now I installed Ruby / Rails / Passenger with nginx (also with Ruby Entreprise Edition) which runs fine on port 3000. Let's say I have a new Ruby on Rails app and would like to host it on myruby.com and not myruby.com:3000.

How should I make this happen?

I configure a domain in nginx as follows:

server {
   listen 3000;
   server_name www.myruby.com;
   root /home/myruby/public; 
   passenger_enabled on;
}

If I change the port to 80 then it's not working (obviously conflicts with Apache). Please note that I do not add the myruby.com domain to the cPanel.

I have 2 dedicated IP addresses. I have heard somewhere that with 2 IPs you can solve this problem. But how do you instruct cPanel's Apache to only listen on a specific IP? Also, if I point a domain to my server how can I instruct the RoR domains to point to the RoR IP?

Any ideas?

Thanks

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

For future reference who tries to run cPanel Apache and Ruby on Rails with nginx.

1) Configure nginx like this:

server {
    listen yourrubydomain.com:8001;
    server_name yourrubydomain.com;
    root /home/yourrubydomain/public; 
}

1) Just add the Add-on domain in cPanel 2) Log in to FTP, navigate to the WWW directory of the newly added domain 3) Create a .htaccess file with the following content:

RewriteRule ^ "http\:\/\/127.0.0.1\:8001%{REQUEST_URI}" [P,QSA,L]

4) That's it! 5) At your second Ruby on Rails domain do not forget to try a different port than the first one. So for example, at mysecondrubydomain.com use port 8002, instead of 8001, both in the nginx and .htaccess configuration.

share|improve this answer
add comment

http://httpd.apache.org/docs/2.2/mod/mod%5Fproxy.html

There you go, learn about mod_proxy and ProxyPass.

share|improve this answer
    
And what do you think of this solution? RewriteEngine on RewriteCond %{HTTP_HOST} ^myruby.com$ [OR] RewriteCond %{HTTP_HOST} ^www.myruby.com$ RewriteRule ^demo "http\:\/\/127\.0\.0\.1\:3000%{REQUEST_URI}" [P,QSA,L] –  James Aug 28 '09 at 14:57
    
Basically, you are proxying without using the mod_proxy module. Congrats, you win. –  Dave Rickman Aug 29 '09 at 7:24
add comment

You can tell Apache to listen only on certain IPs in the httpd.conf file. Default is probably

Listen 80

Change it to

Listen XXX:80

Where XXX is the first IP you want apache to listen on.

You can then set up nginx to listen on the other IP

listen YYY:80

Alternatively, you could configure Apache to use mod_proxy to do a reverse proxy so that certain domains will forward to localhost:3000 and use the nginx server. But I think the above solution is better because it adds less complexity to the system.

Note that you might fight with cPanel on the change because it will tend to re-write that file when it is upgraded or you make changes to domains.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.