-
Notifications
You must be signed in to change notification settings - Fork 0
Website
This page details the details of the website construction. For Server configuration info, check out Hosting Services.
Node react downloads the entire site when opened to enable instant navigation. React Instructions
We use the pm2 utility to automatically run a script on the server to:
- Pull current project from GitHub.
- Run
npm install
to ensure all required modules are installed. - Execute
npm start
to run the 'start' script in npm to start the website.
we run pm2 startup
, and then execute the command returned to ensure pm2 starts when the server boots up.
Resources
- PM2 Deployment Instructions.
- Deploy via PM2 from private github repo.
- Deploy and iterate faster, hello ecosystem.json.
- Tutorial: Creating and managing a Node.js server on AWS.
After creating the pm2 script, and running it, we can use pm2 save
to automatically run it when pm2 is started.
We are currently using nginx to automatically redirect the user from port 80 (default) to port 3000.
This means when a user navigates to valuesfootprint.com, it will automatically show them the correct page. No need to specify port 3000. Both nginx and pm2 are configured to start at launch.
Currently, this is configured at /etc/nginx/nginx.conf.
I restarted the server, but after 10 minutes the site is still not available?
This could be an issue from any number of causes. Such as:
- PM2 process failed. (All startup processes are handled by PM2)
- Automatic Initialisation of
npm start
failed. - One of the likely causes of the above would be due to the website itself is not configured properly.
- The domain (Route53 service) has failed and/or not pointing to the correct resource.
- Nginx process is routing traffic to the wrong port/instance and/or is not configured properly.
Troubleshooting Steps
- If the website is displaying the 'starting up' page, this means the domain is functioning. Otherwise:
- For the domain, refer to Route53 AWS service and make sure the domain is pointing to the correct EC2 instance (Elastic IP). To rule this out, try accessing the Elastic IP instead of valuesfootprint.com. (Currently 13.210.161.77). If this works, that means the domain isn't working.
- If the page cannot be loaded because the SSL certificate is invalid, refer to the Renew SSL Certificate documentation below.
- If the website initiation simply failed, we can double check by connecting to the instance via SSH, then execute 'sudo pm2 status'. The 'Values Footprint Survey' process should be online and only have 0-2 restarts (The ☐ column).
- If the website has more than 2 restarts, we can actually execute some code to check the error logs. Do as follows:
Log-in to the SSH terminal. (Refer to user guide if necessary).
Execute sudo pm2 describe 'Values Footprint Survey'
Then use the 'cat' command to view the error log path listed. For example:
sudo cat /root/.pm2/logs/Values-Footprint-Survey-error-2.log
It is good to know how to manually start the web server, especially if the automatic work-around with pm2 doesn't quite function perfectly.
Execute (in order)
sudo pm2 kill
cd /home/ec2-user/crispy-values
npm install
-
npm start
If the server starts, and you can access the site, it is an issue with the startup process (handled by PM2).
If the server is starting, but not pulling the latest version from git, do the following:
sudo pm2 kill
cd /home/ec2-user/crispy-values
sudo git pull
If an error occurs with git pull, you can try: If an error still occurs with these, you likely need to reconfigure git.
sudo git fetch --all
sudo git reset --hard origin/master
sudo git pull
Otherwise, continue to start the server:
npm install
npm start
NOTE: If the problem was the website not updating, executing sudo reboot
or just restarting the server like normal should start the PM2 process and start the web server properly.
You can configure the PM2 startup scripts on the ecosystem.config.js file.
This file can be found in two directories, as we have one to start the server (including git pull, npm start etc.) and another to automatically renew the SSL certificate (untested).
SSL Certificate Script:
- /opt/letsencrypt/ecosystem.config.js Website Startup Scripts:
- /home/ec2-user/ecosystem.config.js
You can modify the scripts using 'nano' command. Example:
sudo nano /home/ec2-user/ecosystem.config.js
Nano is difficult to first use. To save the changes you make: Ctrl+X then type 'Y' and hit enter.
Refer to the Hosting Services page for instructions to renew the certificate