Multi-domain to multiple roots & one rails-app

Hello,

I wish to consult an configuration for following situation. Thanks for
any suggestion.

I have multi domain rails app and for each domain there is a need for
serving static files outside of rails, each domain from separated path.

so for example:

mydomain.com/one/route
→ will go to rails app

mydomain.com/static/another/route.png
→ will serve file on path /somewhere/mydomain.com/another/route.png

or in general:

DOMAIN/static/PATH will serve file /somewhere/DOMAIN/PATH
and DOMAIN/PATH will go to the rails app

This should work for any sub/domain.

Thanks! All suggestions are welcome.

Hi there,

I dont know if its correct in every case, but I did it like this:

server {
    listen 80;
    server_name _;

    location /x/ {
      alias /somewhere/$host/;
    }

    location / {
      proxy_pass http://127.0.0.1:3000/;
      proxy_redirect off;

      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}

I think you can use your favourite style instead of proxying to 3000.

Thanks & suggestions are welcome.

I would avoid using alias since it’s not mandatory:

server {
listen 80;
server_name ***; # I use one configuration file per domain and for
specific subdomains which have special requirements
root /var/www/$host;
index index.aaa index.bbb; # Depending on our needs
try_files $uri $uri/ /;
}

If multiple place must serve the same content, I may then use symbolic
links in the file system.

For Rails, I can’t give you advice.

B. R.