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
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/
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
I have a ruby on rails application which runs on Middleman Server. I installed that application in windows azure ubuntu virtual machine. After completing installation once i started my server by giving this command "middleman server" my application is running well. After that i have installed apache web server for that application by following this procedure
http://nathanhoad.net/how-to-ruby-on-rails-ubuntu-apache-with-passenger
but im getting this error after completing the above procedure
"it works! this is the default web page for this server. the web server software is running but no content has been added, yet."
Please help me how to install a webserver for a ruby on rails application which normally runs on middleman server.
You said you have Apache installed, there's your web server. And if you installed Passenger you have an application server for your Rails or Middleman. Check out the Phusion Passenger users guide, Apache version. I followed that to set up. Are you trying to view the src as you work or the build after you run middleman build? What are you building, a Rails or Middleman app/site?
I have been messing around with different approaches for Middleman Development setups. I ended trying a few different configurations and documented them in a Gist. Scroll down and there is some info on my Passenger version, I'm very new to MM and that was the first time I tried Passenger, so please take that into consideration. I think the trickiest part was that Passenger requires a public folder, but Middleman doesn't use a public folder at all. I think the Passenger with Middleman has a few more 'gotchas' over the other approaches. Check out the 3.0 in my Gist.
My vhosts file looks like this:
# Testing Middleman Development Approaches #3 with Passenger,
# note the public folder is used to serve the src directory
<VirtualHost *:80>
ServerName mm_passenger.loc
DocumentRoot /Users/davekaplan/mm_passenger/public
ServerAlias mm_passenger.loc.*.xip.io
<Directory /Users/davekaplan/mm_passenger/public>
AllowOverride all
Options -MultiViews
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName mm_passenger.build
DocumentRoot /Users/davekaplan/mm_passenger/build
<Directory /Users/davekaplan/mm_passenger/build>
AllowOverride all
Options -MultiViews
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I'm on Mac running Apache and Passenger. I did a virtual host (path to site files) to the Apache /etc/apache/extra/httpd-vhosts.conf file and the domain to my /etc/hosts file.
Don't give up!
Dave
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?
I have a rails app running on passenger standalone, which is working perfectly. I am running apache, and use a VirtualHost with a reverse proxy to serve my rails app. This works. However my assets are not being served through the vhost, but give a proxy error.
My httpd.conf
<VirtualHost *:80>
ServerName greekpeep_rails.nightowls.co
DocumentRoot /home/railsapps/www/greekpeep/public
ProxyPass / http://127.0.0.1:4000
ProxyPassReverse / http://127.0.0.1:4000
<Directory /home/railsapps/www/greekpeep/public>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
The proxy error
Proxy Error
The proxy server received an invalid response from an upstream server.
The proxy server could not handle the request GET /assets/application- 6fc7d25aa72d2a014ae6b36136c2fbfc.css.
Reason: DNS lookup failure for: 127.0.0.1:4000assets
Note that 127.0.0.1:4000 works perfectly and is correctly serving the assets. greekpeep_rails.nightowls.co loads the page, but not the assets.
Looks like you are missing a / at the end of your ProxyPass definitions.
ProxyPass / http://127.0.0.1:4000/
ProxyPassReverse / http://127.0.0.1:4000/