ssl in localhost using apache and passenger - ruby-on-rails

I am trying to configure SSL on my localhost using apache and phusion passenger. I am using virtualhosts.
I have the below configuration in sites-available/myapp
VirtualHost *:80
ServerName myapp
DocumentRoot /home/madhu/ror/myapp/public
RailsEnv development
Directory /home/madhu/ror/myapp/public
AllowOverride all
Options -MultiViews
Order allow,deny
allow from all
Directory
VirtualHost
VirtualHost *:443
ServerName myapp
DocumentRoot /home/madhu/ror/myapp/public
ProxyPass / http://myapp/
ProxyPassReverse / http://myapp/
ProxyPreserveHost On
RequestHeader set X_FORWARDED_PROTO 'https'
Directory /home/madhu/ror/myapp/public
AllowOverride all
Options -MultiViews
Order allow,deny
allow from all
Directory
SSLEngine On
SSLProxyEngine On
SSLCertificateFile /etc/ssl/certs/Thawte_Server_CA.pem
SSLProxyMachineCertificateFile /etc/ssl/certs/Thawte_Server_CA.pem
VirtualHost
The SSL is enabled and everything works fine. But when I go to the url https://myapp/login , it says "The requested URL /login was not found on this server". When I look at the apache logs I found out that the request is going to /var/www/login istead of /home/madhu/ror/myapp/public. This was the error log
[client 127.0.0.1] File does not exist: /var/www/login
Is there anything I am missing? Please help
Thanks.

I had to put
ServerName myapp
DocumentRoot /home/madhu/ror/myapp/public
RequestHeader set X_FORWARDED_PROTO 'https'
Directory /home/madhu/ror/myapp/public
AllowOverride all
Options -MultiViews
Order allow,deny
allow from all
Directory
SSLEngine On
SSLProxyEngine On
SSLCertificateFile /etc/ssl/certs/Thawte_Server_CA.pem
SSLProxyMachineCertificateFile /etc/ssl/certs/Thawte_Server_CA.pem
in default-ssl :P silly mistake

Related

Proxy Pass Subdirectory in Apache Passenger with Rails App

I have a rails app (www.myapp.com) for which I am using Apache Passenger. The virtual host is configured as follows:
<VirtualHost *:80>
DocumentRoot "/var/www/myapp/current/public"
RailsEnv production
<directory "/var/www/myapp/current/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</directory>
RailsBaseURI /
</VirtualHost>
I have a blog which is hosted externally on some other domain, lets say www.myapp-blog.com. I want to 301 redirect any requests to www.myapp.com/blog or www.myapp.com/blog/* to the relevant pages on www.myapp-blog.com. Everything else should flow through my Rails app.
How should I modify the above virtual host configuration to achieve this?
use apache port forwarding technique...
<VirtualHost *:80>
ProxyPreserveHost On
ProxyRequests Off
ServerName www.myapp-blog.com
ServerAlias myapp-blog.com
ProxyPass / http://www.myapp.com/blog/
ProxyPassReverse / http://www.myapp.com/blog
</VirtualHost>

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>

How to deploy Rails app on subdomain root with Apache and Passenger

I have working Rails app on sub-uri redmine.example.org/redmine and I want it on redmine.example.org
/var/www/work/redmine.src is approot
/var/www/work/redmine is symlink to /var/www/work/redmine.src/public
<VirtualHost *:80>
DocumentRoot /var/www/work
ServerName redmine.example.org
ErrorLog /var/log/apache2/redmine-error_log
CustomLog /var/log/apache2/redmine-access_log combined
<Directory /var/www/work/redmine>
AllowOverride all
Options -MultiViews
Order allow,deny
allow from all
</Directory>
RackBaseURI /redmine
<Directory /var/www/work/redmine.src>
Options -MultiViews
Order allow,deny
allow from all
</Directory>
</VirtualHost>
I tried many combination and googled hours, but nothing works.
How should I change this config to deploy redmine on subdomain root?
Thanks in advance.
Well, it was easier, than I supposed.
When I read the manual again and again I found solution:
link to manual
Now my config file looks like this:
<VirtualHost *:80>
DocumentRoot /var/www/work/redmine.src/public
ServerName redmine.example.org
<Directory /var/www/work/redmine.src/public>
AllowOverride all
Options -MultiViews
Order allow,deny
allow from all
</Directory>
</VirtualHost>
Another way to deploy sub-uri app, might work for you too:
<VirtualHost *:80>
ProxyPass /sub_uri/ http://localhost:8000/sub_uri/
DocumentRoot /main_app/public
<Directory /main_app/public>
...
</Directory>
</VirtualHost>
<VirtualHost *:8000>
DocumentRoot /sub_uri/public
<Directory /sub_uri/public>
...
SetEnv RAILS_RELATIVE_URL_ROOT /sub_uri
</Directory>
</VirtualHost>
I installed Redmine 3.3.1 on a Debian 9.0 Stretch server using the packages provided by the distribution itself (Apache + Redmine + Ruby + Rails + Passenger + MariaDB) more or less following those guides:
http://www.redmine.org/projects/redmine/wiki/RedmineInstall
http://www.redmine.org/projects/redmine/wiki/InstallRedmineOnDebianStableApacheMysqlPassenger
I would like to leave www.example.org "for Apache" and redmine.example.org "for Redmine", so I ended up with the following setup.
I left /etc/apache2/sites-available/000-default.conf untouched and created a file named redmine.conf inside that same folder:
<VirtualHost *:80>
ServerName redmine.example.org
DocumentRoot /usr/share/redmine/public
PassengerRuby /usr/bin/ruby
<Directory /usr/share/redmine/public>
Allow from all
Options -MultiViews
Require all granted
</Directory>
</VirtualHost>
Then, I've linked it to the sites-enabled folder and restarted Apache:
# ln -s /etc/apache2/sites-available/redmine.conf /etc/apache2/sites-enabled/redmine.conf
# systemctl restart apache2
To set up that virtual host, I followed the directions here:
Deploying a Ruby application on Passenger + Apache
Deploying an app to a virtual host's root
https://www.phusionpassenger.com/library/deploy/apache/deploy/ruby/#deploying-an-app-to-a-virtual-host-s-root

my rails application not work on my debian server in production

When I run my browser from my rails application on my debian server, the tree of my application appears in the browser.
I install and configure passenger and apache but it does not work.
Why?
Thanks
You most likely have your web server pointed at <some_path>/app instead of <some_path>/app/public.
Example Apache VirtualHost:
<VirtualHost *:443>
ServerName www.app.com
DocumentRoot "/var/app/current/public/"
CustomLog /var/log/apache2/app_log combined
ErrorLog /var/log/apache2/app_log
<Directory /var/app/current/public>
AllowOverride all
Options -MultiViews
</Directory>
SSLEngine on
SSLCertificateFile /etc/ssl/certs/app.crt
SSLCertificateKeyFile /etc/ssl/private/app.key
SSLCertificateChainFile /etc/ssl/certs/bundle.crt
</VirtualHost>

Share Rails 3 Phusion Passenger Deployment Between HTTP and HTTPS

I have an apache virtual host for port 80 that hosts a rails 3 phusion passenger application. I would like some actions of the application to switch to https (port 443). What is the best way to share one instance of a phusion passenger rails application between two vhosts?
Right now, I have:
<VirtualHost *:80>
ServerName mycompany.com
ServerAlias www.mycompany.com
RackBaseURI /
DocumentRoot /home/ubuntu/mycompany/public
<Directory /home/ubuntu/mycompany/public >
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and
<VirtualHost _default_:443>
ServerName shop.mycompany.com
SSLEngine On
ProxyPass / http://localhost/
ProxyPassReverse / http://localhost/
ProxyPreserveHost On
SSLCertificateFile /etc/ssl/...
SSLCertificateKeyFile /etc/ssl/...
SSLCertificateChainFile /etc/ssl/...
</VirtualHost>
I know this is not ideal at all. There must be a better way. I do not want all requests to go through https due to the overhead.
Mike

Resources