【问题标题】:nginx -AWS EC2 -Angular Subpath not working on direct requestnginx -AWS EC2 -Angular 子路径不适用于直接请求
【发布时间】:2018-05-10 18:22:25
【问题描述】:

我在 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;
        }

这是角码问题还是服务器配置问题? 如何解决?

【问题讨论】:

  • 我认为服务器名称可能是 nginx 中的问题。请尝试使用域名而不是 _ server_name www.abc.com
  • 还是同样的问题...

标签: angular nginx angular5


【解决方案1】:

我不得不用 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;
        }

【讨论】:

    猜你喜欢
    • 2019-01-16
    • 1970-01-01
    • 1970-01-01
    • 2022-07-01
    • 1970-01-01
    • 2017-12-13
    • 2021-03-04
    • 1970-01-01
    • 2014-09-14
    相关资源
    最近更新 更多