ruby on rails 3 - Haproxy + Nginx + Unicorn - Not serving static assets with SSL -


i trying make rails website serve web-pages , assets both, http or https, happens when enter in https mode being redirected http , assets never served https protocol.

my nginx configuration following one:

server {   listen <%= rubber_env.unicorn_listen_port %>;   listen 443 ssl;    ssl_certificate       /etc/ssl/certs/server.crt;   ssl_certificate_key   /etc/ssl/private/server.key;   ssl_session_cache     shared:ssl:10m;    client_max_body_size 4g;   server_name <%= [ rubber_env.domain, rubber_env.web_aliases ].flatten.compact.join(" ") %>;    keepalive_timeout 5;    # location of our static files   root <%= rubber.root + "/public" %>;    location / {     proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;     proxy_set_header host $http_host;     proxy_redirect off;      # if don't find filename in static files     # request unicorn server     if (!-f $request_filename) {       proxy_pass http://unicorn_server;       break;     }   }    location ~ ^/(assets)/  {     expires 1y;     add_header cache-control public;      add_header etag "";     break;     gzip_static on; # serve pre-gzipped version   }      # rewrites requests maintenance.html     # page if exists in doc root. capistrano's     # disable web task     if (-f $document_root/system/maintenance.html)     {       rewrite  ^(.*)$  /system/maintenance.html last;       break;     }      error_page   500 502 503 504  /500.html;     location = /500.html     {       root <%= rubber.root + "/public" %>;     }     error_page 404  /404.html;     location = /404.html     {       root <%= rubber.root + "/public" %>;     } } 

it better if serve static assets nginx in https or http, if not possible, can serve them rails , pay performance penalty, since used in bookmarklet creating.

do know how make nginx config works ssl serving assets?

if need can add unicorn , haproxy configuration too.

thank you!

my solution accept ssl in , serve assets ssl assets.

<%   @path = "/etc/nginx/rubber/unicorn_nginx.conf" %>   upstream unicorn_server {  # socket configured in unicorn.rb  server unix:/var/run/unicorn.sock  fail_timeout=0; }  server {   listen <%= rubber_env.unicorn_listen_port %>;    client_max_body_size 4g;   server_name <%= [ rubber_env.domain, rubber_env.web_aliases ].flatten.compact.join(" ") %>;    keepalive_timeout 5;    # location of our static files   root <%= rubber.root + "/public" %>;    location / {     proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;     proxy_set_header host $http_host;     proxy_redirect off;      # if don't find filename in static files     # request unicorn server     if (!-f $request_filename) {       proxy_pass http://unicorn_server;       break;     }   }    location ~ ^/(assets)/  {     expires 1y;     add_header cache-control public;      add_header etag "";     break;     gzip_static on; # serve pre-gzipped version   }      # rewrites requests maintenance.html     # page if exists in doc root. capistrano's     # disable web task     if (-f $document_root/system/maintenance.html)     {       rewrite  ^(.*)$  /system/maintenance.html last;       break;     }      error_page   500 502 503 504  /500.html;     location = /500.html     {       root <%= rubber.root + "/public" %>;     }     error_page 404  /404.html;     location = /404.html     {       root <%= rubber.root + "/public" %>;     } }  server {   listen 443 ssl;    ssl_certificate       /etc/ssl/certs/server.crt;   ssl_certificate_key   /etc/ssl/private/server.pem;   ssl_session_cache     shared:ssl:10m;    client_max_body_size 4g;   server_name <%= [ rubber_env.domain, rubber_env.web_aliases ].flatten.compact.join(" ") %>;    keepalive_timeout 5;    # location of our static files   root <%= rubber.root + "/public" %>;    location / {     proxy_set_header  x-real-ip       $remote_addr;     proxy_set_header  x-forwarded-for $proxy_add_x_forwarded_for;     proxy_set_header  x-forwarded-proto https;     proxy_set_header  host $http_host;     proxy_redirect    off;     proxy_pass        http://unicorn_server;   }    location ^~ /assets/ {     gzip_static on;     expires max;     add_header cache-control public;   }      # rewrites requests maintenance.html   # page if exists in doc root. capistrano's   # disable web task   if (-f $document_root/system/maintenance.html)   {     rewrite  ^(.*)$  /system/maintenance.html last;     break;   }    error_page   500 502 503 504  /500.html;   location = /500.html   {     root <%= rubber.root + "/public" %>;   }   error_page 404  /404.html;   location = /404.html   {     root <%= rubber.root + "/public" %>;   } } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -