Nginx [SOLVED]: Nginx + Unicorn multiple apps with locations – routing

Nginx [SOLVED]: Nginx + Unicorn multiple apps with locations – routing

Home Forums Nginx Nginx [SOLVED]: Nginx + Unicorn multiple apps with locations – routing

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #4491

    Anonymous

    QuestionQuestion

    I would like to run multiple rails apps with just using different location blocks. Different unicorn workers are started and configured, they are working just fine.

    Every app is under the same folder: /var/www/<app>, so I configured nginx like this:

    root /var/www;
    
    location  /app1/ {
      root /var/www/app1/public;
      try_files $uri/index.html $uri.html $uri @app1;
    }
    
    location  /app2/ {
      root /var/www/app2/public;
      try_files $uri/index.html $uri.html $uri @app2;
    }
    

    My issue is that w/ this ruleset a request (like mydomain/app1/check) comes into my app1 like this: Started GET "/app1/check" for ... I would like to have just Started GET "/check" for ...

    What should i change on my config?

    #4492

    Anonymous

    Accepted AnswerAnswer

    If you don’t want to change your upstream parameters (whatever you are doing in your @app locations), a simple rewrite can help you:

    location /app1/ {
        root /var/www/app1/public;
        rewrite ^/app1/(.*)$ /$1 break;
        try_files /app1/$uri/index.html /app1/$uri.html /app1/$uri @app1;
    }
    

    The break parameter to rewrite will cause nginx to rewrite the URI without actually redirecting or rerouting the request.

    Don’t forget to add the prefix /app1/ to your try_files names, because $uri will already be rewritten at the time try_files runs.

    Source: http://serverfault.com/questions/496665/nginx-unicorn-multiple-apps-with-locations-routing
    Author: Lukas
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.