Nginx的别名不起作用

我正在尝试将位置为^/[a-z0-9]{24}$所有stream量传递到另一个根目录下的index.html。 我有我的configuration如此设置:

 server { listen 80; server_name example.com; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name example.com; root /Users/me/sites/store_front/static; index index.html; try_files $uri $uri/ $uri.html =404; location ~ "^/[a-z0-9]{24}$" { alias /Users/me/web_app/static; try_files $uri index.html; } } 

由于某种原因,当我curl这个URL我得到一个404:

 $ curl -I https://example.com/55c898e7faa137f42409d403 HTTP/1.1 404 Not Found Server: nginx/1.8.0 Content-Type: text/html; charset=UTF-8 Content-Length: 168 Connection: keep-alive 

有谁知道如何得到这个别名工作?

更新:

一个需要注意的是,我需要index.html中的所有相关url才能正确加载:

 <link href="/styles/main.css" rel="stylesheet" type="text/css" <script src="/javascript/main.js"></script> 

这些文件实际上存在于web_app目录中,但nginx尝试从store_front加载它们

谢谢

指向^/[a-z0-9]{24}$index.html是很容易的。 资源文件/styles/main.css/javascript/main.js需要唯一的URI,否则nginx不知道要提供哪些文件。

如果store_front也使用/styles/javascript前缀,则需要隔离单个文件:

 location = /styles/main.css { root /Users/me/web_app/static; } location = /javascript/main.js { root /Users/me/web_app/static; } location ~ "^/[a-z0-9]{24}" { root /Users/me/web_app/static; rewrite ^ /index.html break; } 

如果/styles/javascript^/[a-z0-9]{24}$ URI都是唯一的,那么可以将上述内容合并到一个位置:

 location ~ "^/([a-z0-9]{24}|styles|javascript)" { root /Users/me/web_app/static; rewrite "^/[a-z0-9]{24}$" /index.html break; } 

甚至:

 location ~ "^/([a-z0-9]{24}|styles/main.css|javascript/main.js)" { root /Users/me/web_app/static; rewrite "^/[a-z0-9]{24}$" /index.html break; }