【发布时间】:2014-07-24 03:47:27
【问题描述】:
我正在使用 nginx 编写一个 AngularJS 单页应用程序。
我刚刚从 apache 切换到 nginx,但我无法使我的配置文件正常工作。
我正在尝试将所有内容重写为 index.html 以让 Angular 进行路由。
我的nginx.conf如下:
server {
index index.html;
location / {
expires -1;
add_header Pragma "no-cache";
add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
try_files $uri $uri/ /index.html;
}
}
是否可以像我的.htaccess 那样将我的nginx.conf 文件放在项目根目录中?
【问题讨论】:
-
我不明白为什么您的
try_files不起作用,但要回答您的第二个问题,Nginx 不会加载随机放置在目录中的配置文件。也不应该……这是一个严重的性能问题。你可以在启动时为 Nginx 包含任何你想要的 conf 文件。对我来说,我将配置文件放在代码中的nginx目录中,并让 Nginx 包含projects/*/nginx/nginx.conf。