sudo rm /etc/nginx/sites-enabled/default sudo systemctl restart nginxĬongratulations! You should now have your Node.js application running through Nginx’s reverse proxy server. Now that we’ve set our configuration to work with the application’s entry port you can now go ahead and remove the default configuration and restart our Nginx instance. You can check your Nginx configuration contains no obvious errors using `sudo nginx -t`.
It’s important at this stage to ensure the entry port you are going to be using for your Node.js application is set within the configuration file. Either way, it provides the general direction to take if you want to use socket.io to stop your server.
This new file can be named anything you wish but for this example I am going to go with `app.conf`. npm start (to start your server as usual) npm stop (this will now stop your running server) The above code has not been tested (it is a cut down version of my code, my code does work) but hopefully it works as is. Step 3 - Configuring NginxĪll Nginx configuration files are located within the `/etc/nginx` directory, with the primary configuration file being `/etc/nginx/nf`.įirstly, we are going to create a new configuration file for our application. Now that we’ve installed Node.js v12 and Nginx successfully, the next part of this guide will focus on configuring Nginx to work with your node application’s entry port. sudo /etc/init.d/nginx startĪt this point in the guide you should now be able to see the Nginx default welcome page on your droplet by visiting the droplet’s public IP address (you can find this in the Digital Ocean dashboard or by running `hostname -all-ip-addresses` within your terminal).
Just like with the Node.js installation we can verify our install was successful by checking the Nginx version number `nginx -v`.īy default Nginx will not start automatically on the server, so you will need to use the following command to get everything up and running. We can check our installation was successful by verifying the newly installed Node.js version `node -v`īefore we install Nginx we are also going to make sure our packages are up to date as well using `apt-get update`.
We are also assuming for this example your Node.js application will be running on 127.0.0.1:3000.Īfter accessing your Droplet through SSH we can go ahead and begin installing Node.js v12 (LTS, long term support) with the following commands: curl -sL https: ///setup_12.x | sudo -E bash.