
*เอามาจากบทความเก่าใน medium นะครับ
http://calculator.s3.amazonaws.com/index.html คำนวณค่าใช้จ่าย EC2

ตั้งค่า Location ที่เราอยากให้ Server อยู่ ยิ่งใกล้ คนใช้งาน ดีที่สุด


SSH Key Authentication
ใช้คำสั่ง ssh-keygen เฉพาะเครื่องนั้น
$ ssh-keygen -t rsa
จากนั้นจะได้ Key ขึ้นมา 2 ตัว C:\Users\win10\.ssh
- private key : id_rsa
- public key : id_rsa.pub (นำไฟล์ publicKey ไปว่างใน server)

การตั้งค่าโดเมนใน Route53


การติดตั้ง Nginx (Reverse Proxy Server)
sudo apt-get update && sudo apt-get install nginx
ถ้าติดตั้งเรียบร้อยจะขึ้นแบบนี้

การตั้งค่า nginx configurationได้ที่นี้ /etc/nginx/nginx.conf
เช็ค syntax error sudo nginx -t
เช็ค root default grep "root" -R /etc/nginx/sites-enabled
ตั้งค่า port:3000 เว็บใหม่ใน NGNIX
- เพิ่ม default เว็บใหม่ใน
/etc/nginx/sites-available/โดเมน
vim /etc/nginx/sites-available/โดเมน
# the IP(s) on which your node server is running. I chose port 3000.
upstream app_โดเมน {
server 127.0.0.1:3000;
keepalive 8;
}
# the nginx server instance
server {
listen 0.0.0.0:80;
server_name โดเมน.com โดเมน;
access_log /var/log/nginx/โดเมน.log;
root /var/www/โฟล์เดอร์เว็บไซต์; if ($host ~* ^(โดเมน\.com|www\.โดเมน\.com)$ ){
rewrite ^/(.*)$ http://www.โดเมน.com/$1;
}
# pass the request to the node.js server with the correct headers
# and much more can be added, see nginx config options
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://app_โดเมน/;
proxy_redirect off;
}
}
- หลังจากสร้างเสร็จ ก็ทำการ
sites-enabled
cd /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/โดเมน โดเมน- เปลี่ยนค่า defalt ใน /etc/nginx/nginx.conf แก้ตรง inlucde
include /etc/nginx/sites-enabled/โดเมน
คำสั่งในการ Restart Nginx sudo /etc/init.d/nginx restart
- หลังจากตั้งค่า Nginx เสร็จให้ Restart ทุกครั้ง
ตั้งค่า Permission File เพื่อใช้งาน SFTP
sudo chown -R ubuntu:ubuntu /var/www/html
sudo chmod -R 755 /var/www/html
ติดตั้ง NodeJS และ NPM

sudo apt-get install nodejs
sudo apt-get install npmsudo ln -s /usr/bin/nodejs /usr/bin/node
ติดตั้ง PM2 (production process manager)
เพื่อให้ server ทำงานแม้เราจะปิด command

sudo npm install -g pm2
Start an application
pm2 start app.js
Restart all application
pm2 restart all