1

My application uses a single web app (in HTML and Javascript) to serve multiple (dynamic amount) system.

Systems are distinguished by URL like http://localhost/sites/<system-id>, where system-id allows only lowercase letter.

Suppose that the web app is located in /opt/myapp. How to config that in nginx?

I tried following methods but none works.

location ~ /sites/[a-z]+ {
   alias /opt/myapp;
   index index.html index.htm; 
}

Enter http://localhost/sites/abc/, got 403 forbidden.

Enter http://localhost/sites/abc/index.html, still 403 forbidden and URL auto changed to http://localhost/sites/abc/index.html/

Same result for location ~ /sites/[a-z]+/ {}

I tried

location ~ /sites/[a-z]+ {
   alias /opt/myapp/;
   index index.html index.htm; 
}

Enter http://localhost/sites/abc, URL redirected to http://localhost/sites/abc/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/index.html/

1 Answer 1

2

An alias directive within a regular expression location must form the complete path to the file.

For example:

location ~ ^/sites/[a-z]+(/.*)?$ {
    alias /opt/myapp$1;
    index index.html index.htm; 
}

See this document for details.

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

Comments

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.