SSL with Apache and Passenger - ruby-on-rails

I tried to add SSL support to my server with configuration from http://www.napcsweb.com/blog/2012/07/24/securing-a-rails-app-on-passenger-with-ssl/
#<VirtualHost *:80>
# ServerName 54.215.6.127
# RewriteEngine On
# RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=permanent]
#</VirtualHost>
<VirtualHost *:80>
#<VirtualHost *:443>
ServerName 54.215.6.127
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /home/ubuntu/my_app/current/public
<Directory /home/ubuntu/my_app/current/public>
Satisfy Any
# This relaxes Apache security settings.
AllowOverride all
Require all granted
# MultiViews must be turned off.
Options -MultiViews
</Directory>
#SSLEngine on
#SSLOptions +StrictRequire
#SSLCertificateFile /etc/apache2/certs/54.215.6.127.crt
#SSLCertificateKeyFile /etc/apache2/certs/54.215.6.127.key
</VirtualHost>
See that I commented line to set server to previous state, i.e. non SSL, but now server is unresponsive.
I do have keys as suggested in napcsweb blog: key, csr, and crt.
What am I missing in SSL configuration?
Passenger just stopped working, how could I start it again?
Update
It worked but just with http after change configuration, I commented:
#Satisfy Any
# This relaxes Apache security settings.
#AllowOverride all
#Require all granted
# MultiViews must be turned off.
Options -MultiViews
And restarted server
sudo apachectl restart
sudo service apache2 restart
But anyway, I need to set https.
Update 2
Ports 80 and 443 are listening, but for some reason 443 does not respond.

I had an error in my EC2 security group. I allowed access to port 443 and it worked.

Related

Freebsd 10.1 / Ruby on Rails / Apache 2.4 / Phusion Passenger : client denied by server configuration

I can't get passenger to work with apache24 on freebsd 10.1
If I place the virtualhost below into my httpd.conf not only does a request for the virtualhost return 403 forbidden but also the server's hostname documentroot which is just index.html file without rails returns 403 forbidden also the httpd-error.log only says client denied by server configuration.
I assume passenger is failing to rewrite the requests from /public to /app/views/index.html.erb because I didn't put any html files in
/public Already installed mod_fastcgi but responses are still 403 forbidden
This is the tail of my httpd.conf
LoadModule passenger_module /usr/local/lib/ruby/gems/2.1/gems/passenger-5.0.18/buildout/apache2/mod_passenger.so
LoadModule fastcgi_module libexec/apache24/mod_fastcgi.so
<IfModule mod_passenger.c>
PassengerRoot /usr/local/lib/ruby/gems/2.1/gems/passenger-5.0.18
PassengerDefaultRuby /usr/local/bin/ruby21
</IfModule>
# Virtual hosts
<VirtualHost *:80>
ServerName www.mydomain.com
DocumentRoot /usr/home/myusername/websites/myrailsappname/public
<Directory /usr/home/myusername/websites/myrailsappname/public>
AllowOverride all
Options -MultiViews
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Include etc/apache24/Includes/*.conf
Apache 2.4 has different allow/deny rules:
http://httpd.apache.org/docs/2.4/upgrading.html#run-time
You will want to update your rule:
<Directory /usr/home/myusername/websites/myrailsappname/public>
AllowOverride all
Options -MultiViews
Order allow,deny
Allow from all
</Directory>
to something like:
<Directory /usr/home/myusername/websites/myrailsappname/public>
AllowOverride all
Options -MultiViews
require all granted
</Directory>

Deploy ruby on rails app with passenger and apache

I want to deploy my ruby on rails application on Red Hat Enterprise Linux Server release 6.5 server
I have done the following:
Server version: Apache/2.2.15 (Unix)
rvm install ruby
gem install rails
gem install passenger
passenger-install-apache2-module
then I added the following line on my httpd.conf file
LoadModule passenger_module /home/myname/.rvm/gems/ruby-2.1.2/gems/passenger-4.0.50/buildout/apache2/mod_passenger.so
<IfModule mod_passenger.c>
PassengerRoot /home/myname/.rvm/gems/ruby-2.1.2/gems/passenger-4.0.50
PassengerDefaultRuby /home/myname/.rvm/gems/ruby-2.1.2/wrappers/ruby
</IfModule>
alos I added the following to my httpd.conf
<VirtualHost *:80>
ServerName www.whatever.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/whatever/public
<Directory /var/www/whatever/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
#Require all granted
</Directory>
Additional info
rvm 1.25.31
I restarted the httpd and I cannot see my app running on whatever.com
I have bought the domain and redirected it to the IP of my machine.
What is wrong?
There's a number of reasons why this can happen, #user1876128 had some internal network issues and it wasn't acutally apache at fault.
For this apache setup to work, your network needs to allow http traffic to port 80 of your server box.
It's also advisable to allow traffic on port 3000, so you can run up a rails dev server on the same address (plus :3000) to check any changes before they're up.
You can log in to most domestic routers by pointing your browser at 192.168.0.1 or 192.168.1.1, then using the password (which is either written on your router, or the default password you can find online, or you've already changed it). And setting up a service for port 80 and your server box.
You need to uncomment the line indicated below and restart your apache service (sudo service apache2 restart or similar sudo /etc/init.d/apache2 restart)
<VirtualHost *:80>
ServerName www.whatever.com
# !!! Be sure to point DocumentRoot to 'public'!
DocumentRoot /var/www/whatever/public
<Directory /var/www/whatever/public>
# This relaxes Apache security settings.
AllowOverride all
# MultiViews must be turned off.
Options -MultiViews
# Uncomment this if you're on Apache >= 2.4:
---> Require all granted
</Directory>
This is a common issue with the default stuff from passenger. Chances are you're on a newer version of apache which means # Uncomment this if you're on Apache >= 2.4: would apply.

apache + passenger just listing files in public dir

<VirtualHost *:80>
# ... server name/aliases and such.
DocumentRoot /var/www/html
RackEnv staging
RackBaseURI /extapp/forms
<Directory /var/www/html/extapp/forms>
Options -MultiViews
PassengerRuby /home/pstn/.rbenv/versions/2.1.2/bin/ruby
</Directory>
</VirtualHost>
/var/www/html/extapp/forms is a symlink linking to the public folder of a rails 4 application, all permissions for the directory tree are correct (r+w).
Passenger boots, as per the entry in the logs:
[ 2014-09-08 14:07:17.5896 21559/7f8d77305720 agents/Watchdog/Main.cpp:728 ]: All Phusion Passenger agents started!
However, when I visit the appropriate path, all I get is a directory listing of the files residing in the public folder (i.e. robots.txt et. al.)
Try this
<Directory /var/www/html/extapp/forms>
Options -MultiViews
PassengerRuby /home/posten/.rbenv/versions/2.1.2/bin/ruby
PassengerResolveSymlinksInDocumentRoot on
</Directory>
Then restart the server.
My server config is
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerName mysite
RailsEnv development
DocumentRoot /var/www/mysite/public
<Directory /var/www/mysite/public>
Allow from all
Options -MultiViews
PassengerResolveSymlinksInDocumentRoot on
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/ruby-error.log
CustomLog ${APACHE_LOG_DIR}/ruby-access.log combined
# For most configuration files from conf-available/, which are
</VirtualHost>

Add SSL certificate to rails site, apache2 passenger

I have a linux server running Ubuntu 10.04, apache2 and passenger. Its a 1and1 package and comes with an SSL certificate which has the various .crt and .key files present in /etc/ssl.
I have 3 apps hosted on this server, only 1 of which needs SSL encryption. All of the apps are run as a SubURI, e.g. domain.com/app1, domain.com/app2 etc etc and have symlinks created in /etc/apache2/sites-enabled.
How could I get app3 to use the SSL certificate whilst still remaning under a subURI of the server?
Thanks in advance!
apache2.conf
<VirtualHost *:80>
ServerName domain.eu
DocumentRoot /var/www
<Directory /var/www>
Allow from all
</Directory>
RailsBaseURI /app1
<Directory /apps/app1/public>
Options -MultiViews
</Directory>
RailsBaseURI /app2
<Directory /apps/app2/public>
Options -MultiViews
</Directory>
RailsBaseURI /app3
<Directory /apps/app3/public>
Options -MultiViews
</Directory>

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

Resources