简体   繁体   English

Angular 4/5和Nginx代理:SyntaxError:期望的表达式,得到了“ <”

[英]Angular 4/5 and nginx proxy: SyntaxError: expected expression, got '<'

I'm running 2 sites, one in PHP and one in Angular 5 with nginx proxy on top. 我正在运行2个站点,一个在PHP ,一个在Angular 5 ,顶部是nginx代理。 Here's my proxy config: 这是我的代理配置:

server {
    listen 80;
    listen [::]:80;
    server_name mysite.loc;

    ### php
    location /
    {
        proxy_pass http://127.0.0.1:8080;
        include /etc/nginx/proxy_params;
    }

    ### angular (ng serve --disable-host-check)
    location /dashboard
    {
        proxy_pass http://127.0.0.1:4200;
        include /etc/nginx/proxy_params;
    }

}

Accessing http://127.0.0.1:8080 , http://127.0.0.1:4200 works and that http://mysite.loc displays what is in the PHP site (from port 8080). 访问http://127.0.0.1:8080http://127.0.0.1:4200作品和http://mysite.loc显示的是在PHP网站(从8080端口)。

http://mysite.loc/dashboard also works but Angular outputs this error on the console: http://mysite.loc/dashboard也可以使用,但是Angular在控制台上输出此错误:

SyntaxError: expected expression, got '<'

I tried serving the site using this: 我尝试使用以下方法为网站提供服务:

ng s --disable-host-check --base-href /dashboard/

caused an infinite loop loading sockjs-node resources 导致加载sockjs-node资源的无限循环

Note that the Angular application is newly-set up and that no special routing exists yet. 请注意,Angular应用程序是新设置的,尚无特殊路由。 I figured that the site starting at /dashboard confuses Angular's internal routing mechanism. 我发现以/dashboard开头的站点会混淆Angular的内部路由机制。

Anyone knows how to remedy this problem? 有人知道如何解决这个问题吗? TIA TIA

I had the same, but having 2 react app in one node with nginx, I could fix it with: https://serverfault.com/questions/562756/how-to-remove-the-path-with-an-nginx-proxy-pass/562850#562850 我有相同的内容,但是在一个使用nginx的节点中有2个React应用程序,我可以使用以下方法进行修复: https : //serverfault.com/questions/562756/how-to-remove-the-path-with-an-nginx- proxy-pass / 562850#562850

You can try modifying your nginx config like: 您可以尝试修改您的nginx配置,例如:

    location /dashboard {
            return 302 /dashboard/;
    }
    location /dashboard/ {
            proxy_pass      http://127.0.0.1:4200/;               
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM