upstream app_server {
server unix:/tmp/gunicorn.sock fail_timeout=0;
}
upstream another_server {
server 192.168.128.11;
}
server {
server_name test.com;
listen 80;
location / {
proxy_pass http://app_server;
proxy_set_header Host $host;
}
location ~ \.(js|css|jpeg|jpg|png|gif|ico|mp4|json) {
root /www/app;
try_files $uri /$1/$2.$4;
}
location ~ /anotherapp {
proxy_pass http://another_server;
proxy_set_header Host $host;
}
}我在不同的机器上有两台服务器,我不知道如何处理another_server中的静态文件。
当我获得test.com/anotherapp/index.js资源时,它返回app_server中的文件,而不是another_app服务器中的文件。
问题是如何处理another_app服务器中的静态文件
发布于 2018-06-11 17:57:53
将按顺序计算正则表达式location语句,直到找到匹配的正则表达式。
因此,/anotherapp/index.js先匹配\.(js|css|jpeg|jpg|png|gif|ico|mp4|json),然后再匹配/anotherapp。
您有两个选择:
或者,颠倒正则表达式location块的顺序,以便首先遇到location ~ /anotherapp。
或者,使用带有^~修饰符的前缀location (它将始终优先于任何正则表达式location),例如:
location ^~ /anotherapp { ... }详情请参见this document。
https://stackoverflow.com/questions/50793824
复制相似问题