简体   繁体   中英

Node.js deployment to web

I have a node.js app that is fully built and runs on localhost:3000. I also have a domain name bought. What is the simplest way that I can get that domain to point to my app? When I type in example.com I want to see my app. I do not really know the terms to google this successfully and a lot of ways seem overly complicated. I have already sunk hours into trying to get it deployed on AWS using pivotal web services but it was much more than I needed.

If you're deploying to AWS I recommend trying ElasticBeanstalk (EB). EB makes it exceptionally easy to deploy your app to AWS, and if you follow the steps, you should be able to deploy the first version within an hour, and subsequent versions will be much quicker since you won't be creating a new environment and launching a new instance each time you deploy. You can read more about EB in the AWS docs at http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.html , and there are some great walk-throughs to deploying your app, but they're mostly done via the GUI and, well, I prefer the command line...

To get started with EB, you'll first need to install the aws command line interface, or cli. Follow the instructions for your environment as appropriate here: http://docs.aws.amazon.com/cli/latest/userguide/installing.html .

Once those are installed you'll need to tell the AWS cli what credentials to use. If you're using OSX you can sudo nano ~/.aws/config which will open the AWS configuration file and you can put your credentials in the file like so:

[profile eb-cli]
aws_access_key_id = your-key-here
aws_secret_access_key = your-key-here

Now that you have the cli installed you simply need to initialize ElasticBeanstalk with eb init in the root of your application. The cli will ask you the following questions to configure your application for AWS, and will then deploy your application:

  1. Select a Default Region . I selected us-east-1 as that's the closest region to me, but you can use any region you like.
  2. Select an Application to Use . Since this is your first application you'll have to create a new one. The CLI will recognize the name of the directory and assume that to be the name of the application. You can just hit enter to set that as your application name, or you can name it whatever you like.
  3. It appears your are using Node.js. Is this correct? Yes
  4. Select a Platform version. The most recent platform version is 64-bit Amazon Linux 2016.03 v2.10, stick with the most recent version unless you have good reason to use an older version.
  5. Do you want SSH for your instances? If you select yes, you'll have to select the keypair you want to use. If you haven't generated a keypair, select no for now. If you do want to SSH in later you can create a new keypair and then update your environment in the GUI to use that keypair.
  6. You'll now be taken back to your default command prompt where your next command is eb create . This will create an environment for your application.
  7. Enter Environment Name . Feel free to use the default.
  8. Enter DNS CNAME prefix . Again feel free to use the default.

From here ElasticBeanstalk is going to take over and deploy the application to AWS using the default ElasticBeanstalk settings you selected. You'll get a load balancer with autoscaling policy, an RDS database (if your application calls for it), and an EC2 instance with a public DNS that you can point your domain at.

Your public DNS will have the syntax <the-dns-cname-prefix-you-selected-in-step-7>.<the-region-you-selected-in-step-1>.elasticbeanstalk.com and will look something like myapp-dev-environment.us-east-1.elasticbeanstalk.com . To get it you can simply type eb status at your command line and it'll be there as the CNAME.

Copy your CNAME ( myapp-dev-environment.us-east-1.elasticbeanstalk.com ) and head over to your registrar and open your DNS settings for your domain. Create a new CNAME for your domain with the name www and the value as myapp-dev-environment.us-east-1.elasticbeanstalk.com . Set the ttl to whatever you want and save it.

Go to your browser and type www.yourdomain.com in to your address bar. If you've done everything correctly you should see the index page that your application is serving.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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