Answer the question
In order to leave comments, you need to log in
How to write dynamic location and try_files in NGINX config?
Good afternoon!
There are a bunch of static projects of the same type that are added to the nginx root directory into directories with random names.
For example,
site.ru/ffdsf2425ff
site.ru/2435werw2f
site.ru/ffdsertwet3f
site.ru/ertw3ergeb The
Nginx config now looks like this:
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
}
location ~ /(.*)/(.*) {
try_files $uri $uri/ $1/index.html;
}
Answer the question
In order to leave comments, you need to log in
You almost found the solution, only you missed the "/" at the beginning:
location ~ ^/([a-zA-Z0-9]*)/ {
root /usr/share/nginx/html;
try_files $uri $uri/ /$1/index.html;
}
a tray file does not need to be used at all,
since all codes must be processed by the CMS.
If you have apache + nginx
error_page 401 403 404 405 500 502 503 = @fallback;
location @fallback {
proxy_pass http://127.0.0.1:82;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question