Ask A Question


You’re not receiving notifications from this thread. redirecting subdomains to https

Masud Hossain asked in Servers

I tried out's SSL encrypt for a new domain. And it's rerouting my to the Any way I can keep it from redirecting it to the https for subdomains?

Additional info:

  1. For DNS, I did a CNAME where * is an alias of
  2. Using for pushing code and SSL.
  3. Using digital ocean for my hosting.
  4. Using google domains for my domain (DNS setting is inside digitaloceans though).
Hey Masud.. here is what we have done. We have 2 nginx sites-available files.. look for /etc/nginx/sites-enabled/

1st - SSL_Enabled - Standard Hatch file - Listening to port 80 and 443
2nd - Subdomains - ningx server block - listening to just port 80
server {
  listen 80 default_server;
  listen [::]:80 default_server;

  server_name _;

  passenger_enabled on;
  rails_env    production;
  root         /home/deploy/YOURAPPFOLDER/current/public;

  # Allow uploads up to 100MB in size
  client_max_body_size 100m;

  location ^~ /assets/ {
      gzip_static on;
      expires max;
      add_header Cache-Control public;

  location /cable {
    passenger_app_group_name YOURAPPFOLDER_websocket;
    passenger_force_max_concurrent_requests_per_process 0;

  # redirect server error pages to the static page /50x.html
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
      root   html;

now to enable non ssl sites we would have to remove subdomains from ssl routing.. edit /etc/nginx/snippets/ssl.conf and change the line as below

add_header Strict-Transport-Security "max-age=15768000; includeSubdomains; preload";

add_header Strict-Transport-Security "max-age=15768000; preload";

run service nginx reload and you should be good..

BTW - sites-enabled and ssl.conf will be write protected hence use sudo vim . to access and write to them.. 

let me know if this worked for you..
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 83,038+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.