我正在使用 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;
}
}
是否可以拥有我的
nginx.conf
文件在项目根目录中,就像我的 .htaccess
做过?
最佳答案
您不想在项目根目录中使用 nginx.conf 并且它不是必需的。此外,您不希望直接更改 nginx.conf,而是需要/etc/nginx/sites-available 中不同网站的特定文件,您可以使用 ln
启用该文件。在/etc/nginx/sites-enabled 中。
至于配置:
server {
root /var/www/mysite/; #or whereever your site files are
index index.html;
location /{
try_files $uri $uri/ =404;
}
}
您缺少告诉 nginx 站点所在位置的根部分。
关于angularjs - Nginx 单应用配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24919338/