I have an nginx server running a react single page application, simple stuff:
<code>server{
server_name testing001.example.com;
location / {
root /var/www/testing001;
try_files $uri /index.html;
}
}
</code>
<code>server{
server_name testing001.example.com;
location / {
root /var/www/testing001;
try_files $uri /index.html;
}
}
</code>
server{
server_name testing001.example.com;
location / {
root /var/www/testing001;
try_files $uri /index.html;
}
}
Inside my /var/www/testing001
directory, besides of the app files, i have a directory:
<code>runtimes
runtimes1.js
runtimes2.js
runtimes3.js
...
runtimesdefault.js
</code>
<code>runtimes
runtimes1.js
runtimes2.js
runtimes3.js
...
runtimesdefault.js
</code>
runtimes
runtimes1.js
runtimes2.js
runtimes3.js
...
runtimesdefault.js
I want all the requests to https://testing.example.com/theRuntime.js?id={1,2,3,4}
to:
- serve me the respective file, depending on the id query string
- this is working fine, using:
<code>location ~* ^/theRuntime.js {
if ($arg_id != "") {
set $id $arg_id;
rewrite ^ /runtimes/$id.js last;
}
}
</code>
<code>location ~* ^/theRuntime.js {
if ($arg_id != "") {
set $id $arg_id;
rewrite ^ /runtimes/$id.js last;
}
}
</code>
location ~* ^/theRuntime.js {
if ($arg_id != "") {
set $id $arg_id;
rewrite ^ /runtimes/$id.js last;
}
}
- if the /runtimes/$id.js file doesn’t exist, i want to serve /runtimes/default.js, or even just a common string directly from nginx i don’t care
- This is the part i can’t figure out, i tried many combinations and it either stops serving me any file (404) or, in some cases, it defaults to the root
index.html
- This is the part i can’t figure out, i tried many combinations and it either stops serving me any file (404) or, in some cases, it defaults to the root