I have a some case to map in nginx
- for / it take from the /var/www/html/cont
- for /content/* it take form the var/www/html/cont
- if it is not / and not /content/* the it should take from /var/www/html/web
i am stucking in case 3
Here is my config
location / {
root /var/www/html/cont;
if (!-e $request_filename){
rewrite ^(.*)$ /index.html break;
}
# try_files $uri $uri/ =404;
}
location /content {
root /var/www/html/cont;
if (!-e $request_filename){
rewrite ^(.*)$ /index.html break;
}
# try_files $uri $uri/ =404;
}
Any help appreciated. Thank you
CodePudding user response:
Set root
for server {}
context as root /var/www/html/web;
then
location / {
root /var/www/html/cont;
# your other directives
}
location /content {
root /var/www/html/cont;
# your other directives
}
CodePudding user response:
Here is my solution which works perfectly in as per my use case.
location / {
if ($request_uri = "/") {
set $custom_root /var/www/html/cont;
}
if ($request_uri != "/") {
set $custom_root /var/www/html/web;
}
root $custom_root;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.html break;
}
# try_files $uri $uri/ =404;
}
location /content {
root /var/www/html/cont;
if (!-e $request_filename) {
rewrite ^(.*)$ /index.html break;
}
}