Install Nginx on Ubuntu (AWS EC2): Start It, Enable It, Check It
My Node app runs on port 4000. That means anyone who opens it has to type :4000 at the end of the URL. Real sites don't work like that. The fix is to put a web server in front of the app. In this post I install Nginx on my Ubuntu EC2 server and make sure it stays running. In the next post I point it at the Node app. This is part of my series on deploying a Node.js app to AWS. So far I have an EC2…
To deploy a Node.js application on AWS EC2, you'll need to install and configure a web server like Nginx. Here's how to do it:
1. Connect to your Ubuntu EC2 instance via SSH. Once connected, install Nginx by running the command `sudo apt install -y nginx`. The `-y` flag automatically answers "yes" to any prompts.
2. Start the Nginx service using `sudo systemctl start nginx`. This command initiates the web server right away.
3. To ensure Nginx starts automatically after a server reboot, enable it with `sudo systemctl enable nginx`. This step is crucial, as without it, Nginx will be off after each reboot, leaving your site inaccessible.
4. Verify that Nginx is running by executing `sudo systemctl status nginx`. Look for "active (running)" in green text. If it's not active, there may be an issue with the installation or configuration.
5. Open a web browser and enter your server's public IP address. You should see the familiar "Welcome to nginx!" page, confirming that Nginx is up and running.
Now, Nginx is serving as your web server, but it needs to know about your Node.js application. In the next step, you'll configure Nginx as a reverse proxy, directing traffic on port 80 to your app running on port 4000.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to