deploying a react app to alicloud
- do the nodejs vm dance but come back after step 3
cd /home/<YOUR REACT APP>to go to your react folderyarn buildto build a deployment version. now you can serve the whole thing as htmlsudo ln -s ~/<YOUR REACT APP> /var/www/<YOUR REACT APP>to symlink your files to/var/wwwbecause nginx will only serve files from there. symlink === make shortcutsudo chmod -R 755 /var/wwwto grant permissionssudo nano /etc/nginx/sites-available/reactto open a react settings files for nginx- 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.
sudo ln -s /etc/nginx/sites-available/react /etc/nginx/sites-enabled/reactservice restart nginxorsudo systemctl restart nginx. it it doesn’t do that, perhaps it wasn’t started at all. so `service start nginx nginx commands- go open the ip address and see what’s happening.
- in my case, i had to setup security rules. sigh,
- 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]
refs
use the nano