When I run my Angular project on AWS ec2 in production, it automatically gets changed to the host AWS IP address. I am unable to run my service. Has anyone faced this issue previously? Please help
Console screenshot
You no need to run the environment in the EC2,
Create a production build and deploy the code in the AWS >> Instance >> /var/www/html folder.
Command to build production: ng build --prod --aot
Just checkout the public URL of your EC2 Instance. It should be something like below:
http://ec2-52-204-122-132.compute-1.amazonaws.com
Now, in your Angular code, you must be having a base URL of the API. You should use the base URL of your API something like below:
API Base URL: http://ec2-52-204-122-132.compute-1.amazonaws.com/API-Application
This way, there won't be any IP conversion automatically.
Related
Currently, I'm working on a project which is hosted on Microsoft Azure as a resource. The project is presented on a virtual machine and is operated using commands on the Azure CLI.
Now I've been asked to create a web app for it using Node.js and React.js. I'm totally lost on how to connect the Node.js API to the virtual machine. Is there any way to trigger those Azure CLI commands through a Node.js app. Any help would be appreciated!
EDIT:
Managed to solve the issue. Used this npm package 'ssh-exec' which lets you execute commands on a virtual machine remotely after connecting using IP Address, username, password. Very simple to use.
Link to package - https://www.npmjs.com/package/ssh-exec
Managed to solve the issue. Used this npm package 'ssh-exec' which lets you execute commands on a virtual machine remotely after connecting using IP Address, username, password. Very simple to use.
Link to package - https://www.npmjs.com/package/ssh-exec
There are some few steps to connect Node.js API to VM,
Firstly, we need to clone the project that we will be deploying to the Azure VM. This project is a basic Node.js API with a single endpoint for returning an array of todo objects. Go to the location where you want to store the project and clone it:
git clone --single-branch --branch base-project https://github.com/coderonfleek/node-azure-vm.git
Once the project has been cloned, go to the root of the project and install dependencies:
cd node-azure-vm
npm install
Run the application using the npm run dev command. The application will start up at the address http://localhost:5000. When the application is up and running, enter http://localhost:5000/todos in your browser to see the list of todos.
enter image description here
Now, go to the package.json file of your project and add these scripts in the scripts sections:
"scripts": {
.....,
"stop": "pm2 kill",
"start": "pm2 start server.js"
}
The start and stop scripts will use the pm2 process manager to start and stop the Node.js application on the VM. The pm2 script will be installed globally on the VM when it has been set up.
At the root of the project, run the rm -rf .git command to remove any .git history. Then push the project to GitHub. Make sure that this is the GitHub account connected to your CircleCI account.
Then, Setting up a virtual machine on Azure to run Node.js.
Next, create a new VM on Azure and set its environment up for hosting the Node.js application. These are the steps:
Create a new VM instance
Install nginx
Configure nginx to act as a proxy server. Route all traffic to port 80 on your VM to the running instance of the Node.js application on port 5000
Install Node.js on the VM and clone the app from the GitHub repo into a folder in the VM
Install pm2 globally
Do not be intimidated by the complexity of these steps! You can complete all five with one command. At the root of your project, create a new file named cloud-init-github.txt; it is a cloud-init file. Cloud-init is an industry-standard method for cloud instance initialization.
cloud init- code
(REFER THE BELOW LINK FOR COMPLETE DETAILS)
https://circleci.com/blog/cd-azure-vm/
Sorry maybe it is a dump question but I could not go further.
I got a website which already built with ReactJS and working on AWS Ec2
When I run on localhost
First; in terminal which in file directory run node server.js
yarn start
then I can see the localhost:3000 then when I make any changing just send with SSH and run server with PM2 which pm2 restart server
My question is I want to create a second AWS EC2 instance and run the code there as well when I change config.json which domain is store there I can see a NETWORK ERROR
I created a ec2 instance copied all my files there and I installed NodeJS npm and pm2 but I could not managed see my website on localhost:3000()
What Do I have to do?
You need to use the EC2 public address/IP not localhost
I'm pretty new to DevOps and I'm trying to set up my Node.js app on a AWS server instance. Steps I've taken:
Set up Elastic IP
Launched EC2 instance with Ubuntu server
Connected IP to instance
Allowed incoming connections on port 3000
SSH'd into the server with a .pem file
Now I'm at the point where I need to get my files uploaded to the server. I've used FileZilla (and like it) in the past to upload files but the initial part was already set up. When I set up the site on FileZilla there is no /var/www folder on the remote site.
Don't know how to connect these dots.
Also not sure what I need to run once I successfully upload the files. I imagine npm install when I'm ssh'd into the server? Most of the tutorials out there only go through the basic instance setup.
Thanks!
You don't need to have /var/www. Also, it's better that you use a version control and a remote repository like Github and then SSH to your EC2 and then clone your repository there.
Then cd into your repo and run npm install and then start your app.
And check.
Once you connect to the EC2 instance then clone your code in there. It not mandatory to be in /var/www/html but, it's best practice to keep it there. Once you clone npm install into your project home directory so all the required packages get installed. Then for running your node application in production you have to run it on service as pm2, supervisor, forever, passenger, etc. You can use any of these services and configured appropriately to run your application on desired port. As with pm2, you can follow this guide, install pm2 Then you can run with the following command w.r.t. your environment, like I want to run my application on port 5555 for production
$ PORT=5555 pm2 start app.js --name API --env production -f
Check the status using pm2 list Now, your application is running on http://server-ip:5555/ But, you won't be typing port number every-time. So, you need to configure the web server in front of your application like apache or nginx which will forward all request to your application running port. You could find the best guide to their home page. Then your application is available at http://server-ip/ You can follow this for single configuration of multiple node apps
Hope this helps.
So I have a node js app I would like to deploy to EC2.
I'm planning on creating multiple instances of it and put it beyond Nginx for load balancing.
I know I can use AWS Beanstalk but I think it's over provisioning stuff I don't need.
My question is about the app update process. I thought of two options.
The first one is to create a bare git repository on the EC2 and every time I push some changes, it will hook into the after receive event, create new instances of the app and update Nginx to switch to the new instances.
Another option is to work with Amazon ECR and containers. Every time I update my app image at ECR, it will send an event to the EC2 machine (I'm not sure it is even possiable) to create new instances of the app and again, tell the Nginx to switch.
Which one do you think is preferred?
Here is the deployment method we used
1)Created git bare repo in ec2 server and its tracked with production branch.
2)in the post-receive hook
#!/bin/sh
git --work-tree=/var/www/domain.com --git-dir=/var/repo/site.git checkout -f
cd /var/www/domain.com && npm install && forever restart app.js
3)In the nginx configuration
{
proxy_pass:https://localhost:3000
}
Note:
You can customise post hook to check if its first deployment then run npm install otherwise run npm update.
I hope this will help to solve your issues
I'm developing an app, using MEAN.js and its generator (https://github.com/DaftMonk/generator-angular-fullstack), and Openshift as a hosting.
The project template of the generator includes a script (server/config/seed.js) to populate the database with two users.
In localhost, it is called automatically, but I also can call it using node server/config/seed.js (suppose you're on the root app directory).
The problem is, when I deploy it to Openshift, I run it and no error is reported, but the mongodb database is not updated. The exactly steps I do to run it on Openshift are:
Connect to ssh: ssh ....
cd app-root/runtime/repo/
`node server/config/seed.js``
What am I missing?
Thanks in advance.
You have few options:
in server/config/production.js add
seedDB: true
or change NODE_ENV to development coz during 1st deployment it is set to production
then
grunt
grunt:buildcontrol:openshift
should be working now