gpt4 book ai didi

angularjs - Nginx 单应用配置

转载 作者:行者123 更新时间:2023-12-03 16:57:17 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com