Issue
Good morning
I'm trying to access with nginx directly on one page of my angular application with a parameter in my route. This application is not in the root directory but in a subdirectory myapp http://my_serveur:my_port:/myapp/mypage/myparameter.
I found a lot of solutions to access to a specific route of my angular application when it at the root of the nginx html directory.
location / {
try_files /$uri /$uri/ /roleapp/index.html;
}
But I can't do it when the application is in subdirectory /usr/share/nginx/html/myapp/
I've changed the base href
ng build --base-href=/myapp/
but nginx redirect the application to the index.html of the root directory.
I tried
location /myapp/ {
# alias /usr/share/nginx/html/roleapp/
try_files /myapp/$uri /myapp/$uri/ /myapp/index.html;
}
But Nginx send me back error 500.
Can you help me please?
Goofy
Solution
The $uri
variable already includes the leading /
, so your first try_files
statement should actually look like this:
try_files $uri $uri/ /roleapp/index.html;
In the second case, the value of $uri
already includes the /myapp/
prefix, because the location /myapp/ { ... }
block is only entered if $uri
begins with /myapp/
. So your second try_files
statement should look like this:
try_files $uri $uri/ /myapp/index.html;
See this document for more.
Answered By - Richard Smith
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.