server {
  listen 80;
  listen [::]:80;

  root /var/www/<%= fetch(:stage) %>/<%= fetch(:application) %>/public;
  index index.html index.htm;

  # Make site accessible from http://<%= fetch(:domain_name) %>
  server_name <%= fetch(:domain_name) %>;

  # Passenger
  passenger_enabled on;
  passenger_app_env <%= fetch(:stage) %>;
  passenger_friendly_error_pages on;

  # Logs
  error_log /var/log/nginx/<%= fetch(:application) %>.<%= fetch(:stage) %>.log notice;
  # access_log off;
}
<% if fetch(:stage) == :production %>
server {
  listen 80;
  listen [::]:80;

  server_name  <%= fetch(:domain_name).sub(/www\./, '') %>;
  return       301 http://<%= fetch(:domain_name) %>$request_uri;
}
<% end %>

server {
  listen 80;
  listen [::]:80;

  root /var/www/<%= fetch(:stage) %>/<%= fetch(:application) %>/public;
  index index.html index.htm;

  # Make site accessible from http://<%= fetch(:domain_name) %>
  server_name <%= fetch(:domain_name) %>;

  # Passenger
  passenger_enabled on;
  passenger_app_env <%= fetch(:stage) %>;
  passenger_friendly_error_pages on;

  # Logs
  error_log /var/log/nginx/<%= fetch(:application) %>.<%= fetch(:stage) %>.log notice;
  # access_log off;
}
Add Nginx redirection from no www to www in url
Add Nginx redirection from no www to www in url
