angular - nginx -AWS EC2 -Angular 子路径不适用于直接请求
问题描述
我在 AWS ec2 实例上托管了我的 Angular 项目。实例已成功创建,站点正常工作。
什么时候发出请求 www.abc.com 它可以工作但是当我发出请求 www.abc.com/login 它返回 nginx 错误
404 未找到
app.routing.ts
const routes: Routes = [
{
path: '',
loadChildren: './layout/layout.module#LayoutModule',
canActivate: [AuthGuard]
},
{ path: 'signup', loadChildren: './signup/signup.module#SignupModule' },
{ path: 'login', loadChildren: './login/login.module#LoginModule' },
{ path: 'not-found', loadChildren: './not-found/not-found.module#NotFoundModule' },
{ path: '**', redirectTo: 'not-found' },
];
服务器配置 nginx(启用站点)
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/myfolder;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
这是角度代码问题还是服务器配置问题?如何解决这个问题?
解决方案
我不得不用 index.html 更改 =404
正确的配置是
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/myfolder;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name www.abc.com;
location / {
try_files $uri $uri/ /index.html;
}
推荐阅读
- javascript - 在 HTML 页面中加载本地 three.js 模块失败
- javascript - 如何设置两个元素连续两行浮动?
- java - 我不知道如何使用 CloseShieldInputStream 为扫描仪包装 System.in
- asp.net-core - 带有 OAS3 的 Swashbuckle Swagger UI 挂锁
- amazon-web-services - Logstash Cloudwatch 输入插件未在消息字段中返回任何数据
- python - Pandas DataFrame 嵌套字典 (key+list(key:value))
- linux - 如何识别目录中修改的文件名?
- c++ - 从另一个类访问函数而没有任何关系
- c# - 将 UserControl 添加到面板时为空白(有时)
- spring-boot - 在 2.1.9.RELEASE 上的 Spring Cloud API Gateway 上启用 HTTP/2 支持时出现 ClassCastException