deploying a react app to alicloud

  1. do the nodejs vm dance but come back after step 3
  2. cd /home/<YOUR REACT APP> to go to your react folder
  3. yarn build to build a deployment version. now you can serve the whole thing as html
  4. sudo ln -s ~/<YOUR REACT APP> /var/www/<YOUR REACT APP> to symlink your files to /var/www because nginx will only serve files from there. symlink === make shortcut
  5. sudo chmod -R 755 /var/www to grant permissions
  6. sudo nano /etc/nginx/sites-available/react to open a react settings files for nginx
  7. paste the following:
server {
        listen 80;

        root /var/www/<YOUR REACT APP>/build;
        index index.html index.htm index.nginx-debian.html;

        server_name <YOUR ECS INSTANCE'S PUBLIC IP ADDRESS>;

        location / {
                try_files $uri /index.html;
        }
}

this will tell nginx to serve your index.html files that live in /var/www/<YOUR REACT APP>/build to the <YOUR ECS INSTANCE'S PUBLIC IP ADDRESS> endpoint. replace the ECS instance's IP Address with your domain name if you have one.

  1. sudo ln -s /etc/nginx/sites-available/react /etc/nginx/sites-enabled/react
  2. service restart nginx or sudo systemctl restart nginx. it it doesn't do that, perhaps it wasn't started at all. so `service start nginx nginx commands
  3. go open the ip address and see what's happening.
  4. in my case, i had to setup security rules. sigh,
  5. even after security rules, i found that my symlinks (shorcuts) were broken (the file shows up as red with black background when i call ls). repair it with this.

the reference app [sits on a Hong Kong server, for speedtests from within mainland china for a use case at work]

http://47.52.205.37/

refs

use the nano