Apache virtual host entry to forward non-SSL to SSL for Rails application
Read Time:1 Minute, 11 Second

Apache virtual host entry to forward non-SSL to SSL for Rails application

0 0
0 0

In the rails application, if we need to forward all non-SSL traffic to SSL traffic we can use below virtual host entry.

By default, the rewrite module needs to be enabled in Apache configuration with valid SSL certificates including Chain file.

<VirtualHost *:80>
ServerName mydomain.com
ServerAlias files.mydomain.com
ServerAdmin admin@mydomain.com
DocumentRoot /var/www/html
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteCond %{REQUEST_URI} !^/health_check
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]
ErrorLog /var/log/apache2/errors.log
LogLevel warn
CustomLog /var/log/apache2/access.log combined
SetEnv RAILS_ENV production
<Directory /var/www/html
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>
<VirtualHost *:443>
ServerName mydomain.com
ServerAlias files.mydomain.com
ServerAdmin admin@mydomain.com
DocumentRoot /var/www/html
ErrorLog /var/log/apache2/errors.log
LogLevel warn
CustomLog /var/log/apache2/ssl_access.log combined
SSLEngine on
BrowserMatch "MSIE [2-6]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
# the following ssl certificate files are generated for you from the ssl-cert package.
SSLCertificateFile /etc/apache2/ssl/ssl_certificate.crt
SSLCertificateKeyFile /etc/apache2/ssl/certificate.key
SSLCertificateChainFile /etc/apache2/ssl/ssl_certificate-bundle.crt
SetEnv RAILS_ENV production
<Directory /var/www/html>
Allow from all
Options -MultiViews
</Directory>
</VirtualHost>

Above VirtualHost entry will forward all non-SSL to SSL.

Apache virtual host entry to forward non-SSL to SSL for Rails application 1

About Post Author

Babin Lonston

Overall 14+ Years of experience in the IT field, currently working as a Senior Linux administration with Virtualization & Cloud. Being numismatist for a long time.
Happy
Happy
0 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %

Average Rating

5 Star
0%
4 Star
0%
3 Star
0%
2 Star
0%
1 Star
0%

Leave a Reply

Your email address will not be published.

Previous post Enable setup command in minimal installed Redhat or Centos 6 Linux
Next post Recovering from Ubuntu dual boot issue | Chroot Ubuntu

Subscribe

Subscribe To Our Newsletter

Subscribe To Our Newsletter

Join our mailing list to receive the latest news and updates from our team.

We promise not to spam you, and we don't usually send more than one email a week.

You have Successfully Subscribed!