
Ngữ cảnh:
- Có 1 domain staging.quachson.com được đăng ký ở trang abc
- Có 1 instance beanstalk của amazon tên là aabbcc-09-amazon.com đang chạy nodejs (reactjs), cần cấu hình ssl (https) cho domain staging.quachson.com chỏ vào.
- Cấn https để test, thử nghiệm này nọ, ko có tính chất thương mại điện hay fintech này nọ nên nhu cầu dùng free ssl
Cách làm:
- Tạo SSH
- Tạo pair key
- Add pair key vào beanstalk instance
- Open port 22 cho SSH
- Cấu hình ngnix, install letsencrypt
- Map domain port 80
- Install cerbot.
- Add cronjob 90 ngày.
Chi Tiết:
- Tạo SSH
- Tạo pair key: Services/ec2/NETWORK & SECURITY/ Key Pairs / Create Key Pair
- Add pair key vào beanstalk instance: Services/elasticbeanstalk/ chọn instance / Configuration / Security / Modify
- Open port 22 cho SSH: Services/ec2/Security Groups/ chọn group / Inbound / Edit
- Cấu hình ngnix, install letsencrypt
- From domain staging.quachson.com –> dns record type: A tới IP host.
- From hosting: Maping domain với port 80, tạo mới file: allow-ssl-domain.config, copy vào /etc/nginx/conf.d/elastic-beanstalk
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
server_name staging.quachson.com;
}
-
- Install certbot and ssl
- sudo mkdir -p /opt/certbot
- sudo wget https://dl.eff.org/certbot-auto -O /opt/certbot/certbot-auto;sudo chmod a+x /opt/certbot/certbot-auto
- [nodejs] sudo /opt/certbot/certbot-auto certonly –debug –non-interactive –email son.quach.aavn@gmail.com –agree-tos –domains staging.quachson.com –keep-until-expiring –webroot -w /var/app/current/public
- [java] sudo /opt/certbot/certbot-auto –nginx -d staging.quachson.com
- sudo ln -sf /etc/letsencrypt/live/staging.quachson.com /etc/letsencrypt/live/ebcert
- openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out keystore.p12 -name tomcat -CAfile chain.pem -caname root
- Sau khi install ssl xong, xoá allow-ssl-domain.config vì phải config forward port 80 sang https và SSL chỏ vào file key
- Configuration SSL
- Tạo folder .ebextensions, hỗ trợ .conf và .yaml
- Cấu trúc thư mục cho react project
- Cấu trúc thư mục cho spring boot (Java SE), zip folder .ebextensions và file example-api-2.3.jar -> deployment.zip (tên gì cũng dc)
- Cấu hình cho nginx, nên upload config file lên server rồi restart nginx để test, test thành công thì mới copy vào .ebextensions, upload deployment.zip lên test lại.
- Install certbot and ssl
Một vài lưu ý:
- /etc/nginx
- /etc/letsencrypt/live
- /var/www/html
- sudo service nginx start | stop | restart
- Command check java heap (bytes)
- java -XX:+PrintFlagsFinal {your-java-program} | grep HeapSize
uintx InitialHeapSize := 536870912 {product} uintx MaxHeapSize := 1073741824 {product} uintx PermSize := 67108864 {pd product} uintx MaxPermSize := 134217728 {pd product} intx ThreadStackSize := 512 {pd product}
- Nếu bị lỗi 413 Request Entity Too Large – File Upload Issue thì cách fix như sau: tìm /etc/nginx/nginx.conf
http {
client_max_body_size 100M;
}
nhớ là M, dùng MB hay Mb sẽ hem chạy đâu.
Thảm khảo:
https://gist.github.com/dborin/dd501b28967d3784fa646534dbea6ffa
https://gist.github.com/tony-gutierrez/198988c34e020af0192bab543d35a62a
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-nginx.html
Share 14
NOV
2019
NOV
2019
0