angularjs - Nginx 单应用配置

标签 angularjs nginx

我正在使用 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/

相关文章:

angularjs - 使用Nginx作为代理以避免CORS

php - 从 PHP 获取数据时出现 Angular 未处理的错误

javascript - 使用 Gulp 设置 TypeScript/Angular

javascript - 为什么当我们将 Math.floor 写入 HTML angular 时,Math.floor 什么都不返回?

docker - 错误 : cannot start nginx as networking would not start on alpine docker image

python - 限制登录用户访问静态文件

angularjs - 如何在 Angular JS 的 routeProvider 中传递参数?

javascript - 如何在angularjs中从数据库mysql加载动态记录?

ruby - 我应该以多用户身份安装 RVM 吗?

基于主机名的 Nginx TCP 转发