How to deploy a simple Angular2 app on a shared hosting? [closed]

送分小仙女□ 提交于 2019-12-18 05:06:25

问题


I'd like to deploy my Angular2 app on my shared hosting. I tried transferring the files via ssh, but the app doesn't run. I guess there is something to do like the ng serve on local.

What do are the steps to follow ? I couldn't find them on the internet :/

Thanks

EDIT

I have a very simple app with a few routes and components. No serverside code since I'm calling my REST api for my needs.


回答1:


On your local development machine do an ng build --prod or ng build --prod --aot

This will build your app into the dist folder. Copy the contents of your dist folder to the public directory of your shared hosting.

Depending on your hosting you may need to configure a web server (nginx, Apache, IIS, etc) to serve your files. Don't run ng serve on your shared hosting.

Unless you plan on running your application in Universal mode, where it rerenders pages server side, do not copy your entire app to your shared host. Do not do an npm install on your shared host. Just copy the built application files in the dist folder.




回答2:


You will have to build the app, have a look in package.json in the app root. You will normally have build dev/prod or something along those lines. Then just copy the contents of the dist folder up to the server and make sure that scrips src are correct in the index. file.




回答3:


Of course you have to serve it on the server. There are a few steps you have to take:

  • Transfer your files to the server (think this is done)
  • Login via SSH and execute a npm install inside your app's directory.
  • Change your app.js (or whatever) to bind to your internet interface. The default is to have it bind to localhost so you won't be able to access it from outside your local.
  • You will also need to open the port on the server. This involves using a reverse proxy (like nginx) to listen for a standard port (80) and redirect it to the port your app is listening. If you would like your app to listen on port 80 directly you would need to run it under root user, which is not recommended. Try open the port with a iptables command like: iptables -A INPUT -p tcp --dport 9000 -j ACCEPT
  • Inside your app's directory execute your ng serve (or whatever)

This instructions are for development, not for production use.



来源:https://stackoverflow.com/questions/40854368/how-to-deploy-a-simple-angular2-app-on-a-shared-hosting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!