如何在dev模式下为Angular app设置位置,其中index.html与root不同

时间:2017-05-23 16:45:07

标签: angular nginx digital-ocean

我正在尝试'快速'将我的Angular应用程序以开发模式部署到我的digitalocean droplet - 问题是: node_modules文件夹中的每个文件都抛出了404错误 ,当然除了bootstrap和jquery cdn

我相信这是因为node_modules文件夹位于index.html文件的父文件夹中 - 如何为此应用设置我的nginx默认文件位置?

这是我当前的设置

app文件夹结构

/Root/ 
|- node_modules/
|- src/
|- index.html
|- app/ | - main.ts

NGINX默认文件:

server {
    listen 80;

    server_name xxx.xx.xx.xx;


    location /randomquote {
        alias /var/www/html/randomquotegen/ ;
        try_files $uri/src/index.html $uri/src/index;
    }

}

1 个答案:

答案 0 :(得分:0)

在开发模式下,你可能会运行类似webpack的东西npm start端口4200上的一个小服务器,在生产中你可能只有一个dist/文件夹,而且只需要该静态内容的服务器。我可能会建议一个构建策略,而不是把重量放在你的prod服务器上,但如果你这样做,你就会安装所有的dev依赖项,npm start dev进程和代理nginx,例如:

location / {
          proxy_pass http://localhost:4200;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Host $http_host;
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
    }