我有一个由nginx托管的React SPA。我还使用反向代理将事物转发到api。
但是有时,可能是由于浏览器缓存设置所致,它将加载react应用而不是api页面,就像我要去example.com/api/asdf/
一样。如何强制其使用代理而不是将URL重写为react应用?
server {
listen *:80;
server_name example.com;
index /app/frontend/index.html;
access_log /dev/stdout upstreamlog;
error_log /dev/stderr debug;
location /api {
proxy_pass http://django:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
location / {
root /app/frontend;
index index.html;
try_files $uri $uri/ /index.html;
}
}