0

I have set default root directory as $root to listen on port 80.

Now I want to serve from different directory (share1) if path is started with /user i.e. /user , /user/xyz , /user/abc all should be serve from share1 directory..

map $http_user_agent $root {
    "~*android" /home/vishant/devcenter/wava-v1.1/android;
    "~iPhone" /home/vishant/devcenter/wava-v1.1/ios;
    default  /home/vishant/devcenter/wava-v1.1/ios;
}

server {
    listen 80;

    root $root;
    index index.html;

    location /user {
           alias /home/vishant/devcenter/share1;
    }
}

In short i want something like below..though it's not correct...

location /user/* {
    alias /home/vishant/devcenter/share1;
}

I want all the request starting with /user (/user/abc , /user/xyz) should hit the index.html file.

1 Answer 1

0

To make it clear and working you can divide main / and /user root.

map $http_user_agent $root {
    "~*android" /home/vishant/devcenter/wava-v1.1/android;
    "~iPhone" /home/vishant/devcenter/wava-v1.1/ios;
    default  /home/vishant/devcenter/wava-v1.1/ios;
}

server {
    listen 80;

    location / {
        root $root;
        index index.html;
    }

    location /user {
        alias /home/vishant/devcenter/share1;

        rewrite ^(.*)$ /user/index.html last;
    }
}

It should match everything starting with /user and alias to specified path.

Sign up to request clarification or add additional context in comments.

6 Comments

tried implementing this.. but didn't work.. /user/abc still get 404 Not Found
does the file exist then? ;)
i have only index.html file & i want to call index.html. not others.
Then add rewrite rule, added example to answer.
tried your solution but didn't work... same 404 Not Found :(
|

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.