Reputation: 243
I have an application using Angular 4 and Node.js that I run in development mode with angular-cli and nodemon.
Obviously Angular runs on :4200 and Node.js runs on :3000, and I made a proxy.config.json
to redirect /api
requests to :3000 as below:
{
"/api/*":{
"target":"http://localhost:3000",
"secure":false,
"logLevel":"debug"
}
}
I run the project using two scripts that I defined in my package.json
:
"server": "nodemon server/server.js --watch server",
"dev": "ng serve --proxy-config proxy.config.json"
Now I want to go through the production mode and deploy my application on a VPS. What is the best way to run this application on a VPS?
Upvotes: 2
Views: 2539
Reputation: 4207
With an Apache server, you can use Location
and ReverseProxy
to expose your Node.js API:
/etc/apache2/site-availables/your-project.conf (on the <VirtualHost:.80>
block, after DocumentRoot
for example):
ProxyRequests Off
ProxyPreserveHost On
ProxyVia Full
<Proxy *>
Require all granted
</Proxy>
<Location /api>
ProxyPass http://127.0.0.1:3000
ProxyPassReverse http://1127.0.0.1:3000
</Location>
And then you can use pm2
to keep your Node.js application up in the background: How To Set Up a Node.js Application for Production on Ubuntu 16.04
For the Angular project, simply build it for a production environment: ng build --prod (--aot)
Transfer the generated files on your server, and point your VirtualHost on it.
Upvotes: 2