I am trying to host two react applications using nginx, everyting works expect query params ?test=1
location / {
alias /root/phone_build/;
index index.html;
try_files $uri /index.html$is_args$args =404;
}
location /web_build {
alias /root/web_build/;
index index.html;
try_files $uri /index.html$is_args$args =404;
}
#location / {
location /api {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
proxy_connect_timeout 300s;
proxy_cache_bypass $http_upgrade;
}
I tried with ?$query_string but still doesn't work. Any recommendations? Thank your
CodePudding user response:
You are using try_files
incorrectly. The file terms match filenames and do not need the $is_args$args
, otherwise, when you add a query string to the request, you will simply force a 404
response.
Also, use root
instead of alias
. The alias
directive is only required for special cases.
Try:
index index.html;
location / {
root /root/phone_build;
try_files $uri /index.html =404;
}
location /web_build {
root /root;
try_files $uri /web_build/index.html =404;
}
location /api {
...
}