5

I need to open the landing page on /, and vueJS application on /app. Here is my current nginx setup:

server {
    listen 80;

    location /app {
            alias /var/www/app/dist/;
            try_files $uri $uri/ /index.html;
    }

    location / {
            alias /var/www/landing/dist/;
            try_files $uri $uri/ /index.html;
    }
}

It opens landing on /, and vueJS app when I go to /app, however, if I open /app/login it goes to landing page instead of vue application. What am I doing wrong ?

5
  • And which file should be opened in this case? [..]/app/dist/index.html? Commented Dec 6, 2017 at 16:42
  • Yes, everything starting with /app should open /app/dist/index.html Commented Dec 6, 2017 at 16:44
  • Try: alias /var/www/app/dist; without the trailing /. Commented Dec 6, 2017 at 17:05
  • Returning same result Commented Dec 6, 2017 at 17:21
  • Thank you @RichardSmith, I removed the trailing / + added try_files $uri $uri/ /index.html last;, the last to /app and it worked. Commented Dec 6, 2017 at 18:48

1 Answer 1

9

I have no idea why, but adding last to vue application configuration fixed it. Here is how the config looks now:

server {
    listen 80;

    location /app {
        alias /var/www/app/dist; # removed the / at the end
        try_files $uri $uri/ /index.html last; # here is the trick
    }

    location / {
        alias /var/www/landing/dist/;
        try_files $uri $uri/ /index.html;
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

From nginx.org/en/docs/http/ngx_http_rewrite_module.html - last stops processing the current set of ngx_http_rewrite_module directives and starts a search for a new location matching the changed URI.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.