Hosting two rails app on single server with same IP - ruby-on-rails

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>

Related

Can Apache virtual hosts be set up to redirect to a Docker container?

I have a Docker container running Apache that is currently listening to the port 80.
I am trying to run another website on the same server, using Apache natively this time, also listening to the port 80.
The problem is that I cannot have both applications listening to the same port (Docker and Apache).
Can I set up the server’s native Apache installation to redirect internally certain requests based on the domain name to my Docker container? For instance, Apache would listen to the port 80 and requests to mycontainer.com would be internally transferred to the port 9999 to which Docker would listen.
Yes, you can do that. The first time I wanted to test, this is the way I did and worked with no issue.
We have an Apache container running to port 80, and let us call another domain like mycontainer.com that we want to be accessible on port 80 too but we cannot.
No matter how do you run these containers, I mean by docker run or docker-compose, but the point is they should be in the same network.
Create a network called my_network:
docker network create my_network
I call the first Apache as main and the latter as the_name one.
So now let us run both in the same network:
docker run --name main --network my_network httpd
docker run --name the_name --network my_network another_image
Now you can exec into the the_name container and create a domain.conf file in Apache conf path with below contents:
<VirtualHost *:80>
ServerName mycontainer.com
ProxyPreserveHost On
ProxyPass "/" "http://the_name:9999/"
ProxyPassReverse "/" "http://the_name:9999/"
ProxyRequests Off
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I Guess it is possible with Apache named virtual host and Proxy Pass.
You can try something like below. Just make sure you enabled apache mod_proxy.
NameVirtualHost *:80
<VirtualHost *:80>
ServerName app-running-in-docker-container.com
ErrorLog "var/log/container_error_log"
CustomLog "var/log/container_access_log" common
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass / http://127.0.0.1:999
ProxyPassReverse / http://127.0.0.1:999
</VirtualHost>
<VirtualHost *:80>
ServerName app-running-natively.com
DocumentRoot /path/to/project/doc/root
ErrorLog "var/log/nativelyapp_error_log"
CustomLog "var/log/nativelyapp_access_log" common
</VirtualHost>

wamp server 3.2.2 named vhost in LAN

I want a project hosted on 192.168.10.18/WAMP to be access from all pcs in LAN using a domain name
it is hosted on port 82
I can access using www.project1.ae:82
but if I put just www.adcspos.ae it is showing me the IIS bcz port 80 is used by IIS.
I can not move it to port it, I want to access it without mentioning port on client side while on server it should be hosted other than port 80.
1- 192.168.10.18/v-hosts
<VirtualHost *:82>
ServerName www.project1.ae
ServerAlias localhost
DocumentRoot "${INSTALL_DIR}/www/project1"
<Directory "${INSTALL_DIR}/www/project1">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
# Require local
Require all granted
</Directory>
</VirtualHost>
2- 192.168.10.18/httpd.conf
Listen 0.0.0.0:82
Listen [::0]:82
3- firewall port 82 allowed
4- Client-PC host file
192.168.10.18 www.project1.ae
Can I mention port here in client host or it should be handled at server.

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!

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

First time deploying rails app, cant get passenger to work?

Used railsready, then passenger w/ apache2, finally copied my app to /home/myapp.
Inserted the passenger config lines into /etc/apache2/apache.conf at the bottom along with my virtual host settings:
The servers name is rails.
LoadModule passenger_module /home/myapp/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /home/myapp/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7
PassengerRuby /home/myapp/.rvm/wrappers/ruby-1.9.2-p180/ruby
<VirtualHost *:80>
ServerName rails
DocumentRoot /home/myapp/public
</VirtualHost>
All I get is the apache "It Works" page when I open the IP address. Am I doing something wrong?
You declared a ServerName so you must use it to access this VirtualHost (and not the IP address as you mentioned). Connect to http://rails/
For this to work, the hostname rails must resolv to your server's IP. You can add it to you hosts file or use a real domain name configured to resolve to this IP.
Or you can change the DocumentRoot of the default VirtualHost of Apache, and then it will always respond with the Rails app.
Try:
<VirtualHost *:80>
ServerName rails
DocumentRoot /home/myapp/public
<Directory /var/www/robox/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
Also, you might need to disable the default site. In Ubuntu you can do this with:
[sudo] a2dissite default
[sudo] service apache2 restart

Resources