ruby on rails - Multiple subdomains keep redirecting to root path -


i have 1 rails app running on digital ocean unicorn, nginx on ubuntu , i'm trying handle bunch of subdomains such app1.example.com, app2.example.com, etc.

in routes i'm doing this:

constraints(subdomain)   match '/', to: 'pages#landing', via: [:get, :post] end 

which helping me catch subdomain prefixes , show corresponding landing page controller. locally works great nginx seems redirecting root path of app no matter what.

here nginx config:

upstream app_server {   server unix:/var/run/unicorn.sock fail_timeout=0; }  server {   listen 80;   server_name example.com *.example.com;   return 301 https://$server_name$request_uri; }  #when wildcard above didn't work,  #i tried hardcoding below still nothing server {   listen 80;   server_name app1.example.com;   return 301 https://$server_name$request_uri; }   server {   root /home/rails/example/public;   index index.htm index.html;   listen 443 ssl spdy;   listen [::]:443 ssl spdy;   ...   ssl_protocols tlsv1.1 tlsv1.2;   # ssl_ciphers   ssl_prefer_server_ciphers on;   add_header strict-transport-security max-age=15768000;   ssl_stapling on;   ...   resolver 8.8.8.8 8.8.4.4 valid=86400;   resolver_timeout 10;    location / {     try_files $uri/index.html $uri.html $uri @app;   }    location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {     try_files $uri @app;   }    location @app {     proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;     proxy_set_header host $http_host;     proxy_redirect off;     proxy_pass http://app_server;   } } 

what missing here?

i think should using $host variable rather $server_name, $server_name can first value in list of hostnames , want use hostname user has specified in http headers.

server {   listen 80;   server_name example.com *.example.com;   return 301 https://$host$request_uri; } 

also if hard coded example after wildcard server block wouldn't ever matched because requests match 1 before , thats why didn't work.

related question


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -