NGINX 和 Angular 2 [英] NGINX and Angular 2

查看:21
本文介绍了NGINX 和 Angular 2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的应用程序用户路由像这样/myapp/、/myapp//、/myaapp/dept/

My current app users routes like this /myapp/, /myapp//, /myaapp/dept/

我的应用程序目前部署在带有 NGINX 的内部 http 服务器中.接受外部流量的另一台服务器也运行 NGINX 并将其转发到内部服务器.

My app is currently deployed in an internal http server with NGINX. The other server that accepts external traffic, also runs NGINX and forwards it to the internal server.

我已根据文档将 baseref=/myapp 添加到 index.html

I have add baseref=/myapp to the index.html as per documentation

如果用户访问 http://www.myexternalserver.com/myapp,则该应用程序正常运行完美.如果用户在页面内并单击内部链接,例如http://www.myexternalserver.com/myapp/myparameter,它有效.浏览器中的 url 更改,页面按预期显示.我猜它是由 Angular 2 处理的.

If the user goes to http://www.myexternalserver.com/myapp, the app works perfectly. If the user is inside the page and clicks on an internal link like http://www.myexternalserver.com/myapp/myparameter, it works. The url in the browser changes, the page is displayed as intended. I am guessing it's processed by Angular 2.

不幸的是,当用户直接输入网址时:http://www.myexternalserver.com/myapp/myparameter,我收到 NGINX 的 404 错误.

Unfortunately when a user types in the url directly: http://www.myexternalserver.com/myapp/myparameter, I get a 404 error made by NGINX.

我想我必须配置 NGINX 设置,但我不知道应该如何修改 NGINX 的配置或将什么放入站点可用/默认文件/

I think I have to configure NGINX settings but I don't know how should modify NGINX's config or what to put in the sites-available/default file/

推荐答案

我刚刚遇到了同样的问题并找到了解决方案.但是,我的基本 href 是/".

I just had this same issue and found a solution. My base href is "/", however.

下面是我的 nginx.conf:

Below is my nginx.conf:

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  mysite.com www.mysite.com;
        root /usr/share/nginx/html;

        location / {
            try_files $uri$args $uri$args/ /index.html;
        }
    }
}

这篇关于NGINX 和 Angular 2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆