Nginx单个应用程序配置

gui*_*sen 7 nginx angularjs

我正在使用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;
  }
}
Run Code Online (Sandbox Code Playgroud)

是否有可能nginx.conf像我.htaccess一样将我的文件放在项目根目录中?

Fou*_*rth 9

你不想在项目根目录中使用nginx.conf,而且没有必要.此外,您不希望直接更改nginx.conf,而是希望在/ etc/nginx/sites- 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;
 }
}
Run Code Online (Sandbox Code Playgroud)

您缺少告诉nginx站点所在位置的根部分.