I have an application developed on Rails4 and Ruby2 and i have an issue with this application on production.
Actually i am redirecting every user to his subdomain and from there user can manage his account, but the problem is that App is working fine on the main domain like: www.domain.com
but when user being redirected to his subdomain like: subdomain.domain.com then getting Server not found.
and locally it is working fine with the help of lvh.me all subdimains and everything.
I am using Apache2+Passenger On server.
Is there anything which i have to change in my Apache config ?
<VirtualHost *>
ServerName www.domain.com
ServerAlias domain.com *.domain.com
DocumentRoot /home/deploy/myapp/public
<Directory /home/deploy/myapp/public>
Allow from all
</Directory>
</VirtualHost>
Thanks
Middleware
I've found the best way to handle subdomains with Apache is to rely on the Rails middleware. It's not as efficient as I would like, but equally effective.
You can do this:
#etc/apache2/apache2.conf
<VirtualHost *:80>
ServerName www.domain.com
ServerAlias domain.com
DocumentRoot /home/deploy/myapp/public
<Directory /home/deploy/myapp/public>
Allow from all
</Directory>
</VirtualHost>
If you use a wildcard DNS setting for your subdomain, you'll be able to route all your incoming "subdomain" requests to your domain, allowing Rails to determine the routing based on the subdomain
Related
I'm having trouble setting up my Rails application to successfully use SSL. The stack is using apache, puma and ubuntu. My app is running on port 3000.
Without SSL I had the app up and running great. Now, the only thing shown at the my URL is the /var/www/myapp/public directory listing. I just can't get my Rails app to show.
The app is successfully redirecting all http traffic to https.
Can anyone with a successful setup share their sites-available config files, or suggest changes to mine below? I have a feeling there is a single line somewhere I'm missing. This is my first time trying to get an SSL cert rails app server up and running.
I don't understand how my app running at port 3000 is supposed to show up when viewing the site via SSL on port 443.
Here is my sites-available setup:
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin admin#<MYAPP.COM>
ServerName <MYAPP.COM>
DocumentRoot /var/www/<MYAPP>/public
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLCertificateFile /etc/ssl/certs/<MYAPP.crt>
SSLCertificateKeyFile /etc/ssl/private/<MYAPP.key>
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
</IfModule>
Been banging my head against Google for the last 5 hours. Any help is much appreciated.
You need to configure apache as a reverse proxy.
ProxyPass / http://localhost:3000/
ProxyPassReverse / http://localhost:3000/
Same question asked multiple times but no feasible answer is available yet and also the available answers just support hard coded subdomains:
I applied dynamic subdomain in my rails 3.2.13 app and its working locally by using lvh.me instead of localhost as specified by rails cast.
My urls are like
local
subdomain.app_name.lvh.me:3000/
In porduction:
subdomain.app_name.abc.com/
My site is on appache + passenger
and it seems that appache not forwarding request to passenger.
Am I missing something?
I followed this
http://railscasts.com/episodes/221-subdomains-in-rails-3
Note:
I don't need hardcoded subdomains as they will be generated dynamically and at extensive level.
1) Point *.abc.com in your DNS setup to your server.
2) Setup an Apache vhost to catch the star pointer:
<VirtualHost *:80>
ServerName abc.com
ServerAlias *.abc.com
DocumentRoot /home/public_html/yourapplication/current/public
</VirtualHost>
I deployed using phusion passenger on apache2 intially with just my single Rails application onto a domain, say bar.com. Now I wish to push an additional app I recently created to a subdomain on the bar domain, say foo.bar.com. I was a little confused about how I should setup the virtualhosts in the httpd.conf file to allow for this setup. I setup my DNS through godaddy so that the new subdomain would point to the same ip address as the initial domain (they're both residing on the same server).
Here's the VirtualHosts in my httpd.conf file (notice the two document roots points to different applications):
NameVirtualHost *:80
<VirtualHost *:80>
ServerName bar.com
ServerAlias www.bar.com
DocumentRoot /home/me/app1/public
<Directory /home/me/app1/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName foo.bar.com
ServerAlias foo.bar.com www.foo.bar.com
DocumentRoot /home/me/app2/public
<Directory /home/me/app2/public>
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
With this setup I can navigate to www.bar.com or bar.com but it seems the subdomain doesn't work, navigating to foo.bar.com leads me to this page:
Not Found
The requested URL / was not found on this server.
Apache/2.2.20 (Ubuntu) Server at foo.bar.com Port 80
This involved a couple of steps. Firstly I moved my virtualhosts outside of my httpd.conf file and create to new files under the sites-available folder each named after the corresponding domain bar.com and foo.bar.com. Next I had to add each site to sites-enabled by running the apache command sudo a2ensite. Finally I had to call the command sudo service apache2 reload. It's important that each command was run with admin access or else it didn't work.
Also worth mentioning, browsers like Firefox like to cache old website domain name data so if the url foo.bar.com previously wasn't working and you resolve the problem it will still appear to not work until you clear your cache.
Did you remember to restart apache after adding the second virtual host?
Can anyone provide a link to a description or tutorial dealing with the setup of https and installint certs etc using the Ruby RACK webserver?
Thanks
Rack isn't a webserver, it's an interface between webservers (like Apache, nginx) and applications middleware.
If you're wanting to deploy a Rails application behind SSL, it's as easy as setting up SSL in your web server software. There are special things you can do in your app (such as forcing login pages to always use SSL), but they're outside of the scope of the deployment itself.
For example, to set up SSL with Apache and passenger, you would just configure your vhost as you'd configure any vhost with SSL:
<VirtualHost *:443>
RailsEnv production
PassengerRuby /opt/ruby-enterprise-1.8.6-20080810/bin/ruby
ServerName www.domain.com
SSLEngine on
SSLCertificateFile /etc/certs/appname.crt
SSLCertificateKeyFile /etc/private/appname.key
SSLCertificateChainFile /etc/certs/CompanyIssuingCA1.crt
SSLProtocol all -SSLv2
DocumentRoot /var/www/rails/appname/public/
ErrorLog /var/www/rails/ccell/log/apache.log
<Directory /var/www/rails/appname/public/>
Options ExecCGI FollowSymLinks
AddHandler cgi-script .cgi
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
The webserver itself handles all of the SSL work before it ever gets to the app. Rails (and Rack) don't need to anything special to run on a secured SSL connection; you'd just point your users to https://yourdomain.com and it works.
If you need help installing certificates for your server, try the links below:
Apache: http://www.digicert.com/ssl-certificate-installation-apache.htm
nginx: http://www.digicert.com/ssl-certificate-installation-nginx.htm
I have an apache server running, with mongrels underneath running rails. The apache config file for my rails app looks like this:
<VirtualHost *:80>
ServerName trunk.production.charanga
ServerAlias max.trunk.production.charanga
DocumentRoot /home/max/work/e_learning_resource/trunk/public
RewriteEngine On
<Proxy balancer://mongrel1>
BalancerMember http://127.0.0.1:5010
</Proxy>
# Redirect all non-static requests to thin
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel1%{REQUEST_URI} [P,QSA,L]
ProxyPass / balancer://mongrel1/
ProxyPassReverse / balancer://mongrel1/
ProxyPreserveHost on
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# Custom log file locations
ErrorLog /home/max/work/e_learning_resource/trunk/log/error.log
CustomLog /home/max/work/e_learning_resource/trunk/log/access.log combined
</VirtualHost>
I thought that this would let me access it from another computer with max.trunk.production.charanga, but there's another step i'm sure, that i can't figure out. At the moment, if i type my ip address into the address bar in firefox on another computer, i see the default apache server (with "It works!" etc), but i can't get to my rails apache server. Please correct me if i'm using the wrong terminology here...
thanks
max
The computer attempting to access it needs to know how to resolve the DNS entry max.trunk.production.charanga to the correct IP address 192.168.1.42 (or whatever is the IP address of your server). It cannot figure this out without being told.
You can usually tell it this information by editing /etc/hosts and pointing that address to the correct IP address. Just simply having Apache recognize the name doesn't allow your other machines to know how to access it.
Alternatively, if you run a local DNS service, you can add an entry there.
Editing of your hosts file is a quick and easy solution.
Adding the line
192.168.1.1 trunk.production.charanga max.trunk.production.charanga
to it will tell your computer to use that ip for that domain. Depending on your browser (Firefox does caching internaly) or your OS (windows caches as well), you may need to restart your browser or flush your dns cache.
For more information about your hosts file (including where to find it on different OSes), check this wikipedia link.
I think it just simple,
I always do like this. example . 200.100.10.1:3000/ . I access my friend web application in another city.
or
<VirtualHost>
DocumentRoot /htdoc/trunk/ <-- this is my app path. I move my rails app into xampp for exp
ServerName 200.100.10.1:3000
ServerAlias 200.100.10.1
</VirtualHost>
so I just type 200.100.10.1 to access their application if i'm not wrong. I hope it work
I found the answer: the solution is to make the required server the default server for my ip address. I did this by changing the top of the config file for the required site (/etc/apache2/sites-available/001-trunk in this case)
from this
<VirtualHost *:80>
ServerName trunk.charanga
ServerAlias max.trunk.charanga
DocumentRoot /home/max/work/e_learning_resource/trunk/public
......etc
to
NameVirtualHost 192.168.0.234:80
<VirtualHost 192.168.0.234:80>
ServerName trunk.charanga
ServerAlias max.trunk.charanga
DocumentRoot /home/max/work/e_learning_resource/trunk/public
.....etc
where 192.168.0.234 is my network ip address.
Now, when someone else enters that ip in a browser they get the site i want them to get instead of the apache default site.
Thanks everyone for your advice!
type in the ip and port like so:
127.0.0.0:80/rails
this will only work if permissions are set to read/write.