舊年係GCP用”WordPress Certified by Bitnami”,原來佢地個個Base Image 係Debian 8. 上兩個月收到通知要更新,今個weekend趁住有時間順便一次過upgrade。今次會試下”Nginx WordPress with NGINX and SSL Certified by Bitnami“,睇下用Nginx會唔會快過Apache。
1. New VM
首先登入GCP,左上角Menu > MarketPlace,然後搜尋 WordPress,再揀Nginx WordPress with NGINX and SSL Certified by Bitnami,按Launch on Compute Engine button。
因為Free Tier 嘅關係,記住要揀係美國嘅region,同 f1-micro instance. Disk size 30GB 以下就得, 我自己用15GB. info: https://cloud.google.com/compute/pricing#freeusage
2. Backup
等緊個VM create嘅時候,可以就係用緊嘅WordPress 做 Backup。Install “All-in-One WP Migration” plugin, Export everything. 詳細資料:https://docs.bitnami.com/aws/how-to/migrate-wordpress/,Backup 完然後power off
3. Migrate
個新VM 起好之後,In VPC network > External IP address,這個舊嘅static IP 轉去新 VM 到,然後ssh to new VM, restart all services
1 |
sudo /opt/bitnami/ctlscript.sh restart |
再登入新WordPress,check 返site setting同user email address ,如果係 IP address 就改番做Domain name。
終於係時候Import返 data: All-in-One WP Migration > Import,upload the backup file.
Disable bitnami logo:
1 2 |
sudo /opt/bitnami/apps/wordpress/bnconfig --disable_banner 1 sudo /opt/bitnami/ctlscript.sh restart nginx |
搞掂。
當一切安好之後,就可以Delete 舊VM & snapshot。
(Optional 1)
用Let’s encrypt & Cloudflare SSL strict mode:
一直用開 Cloudflare 免費CDN & FleixSSL,而家用 Lets encrtpy 其實可以唔使用 Cloudflare SSL, 不過費事大搞, 轉做strict mode 算.
in ssh shell:
1 |
sudo /opt/bitnami/letsencrypt/scripts/generate-certificate.sh -m YOURMAIL -d YOURDOMAIN -d www.YOURDOMAIN |
我揀左 Yes 但係個crontab 都係冇野,要手動加返上去。
1 2 3 |
crontab -e 0 0 1 * * sudo /opt/bitnami/letsencrypt/lego --path="/opt/bitnami/letsencrypt" --email="YOURMAIL" --domains="YOURDOMAIN" renew && sudo /opt/bitnami/nginx/sbin/nginx -s reload |
(Optional 2)
redirect HTTP to HTTPS in nginx
如果唔用 Cloudflare redirect,可以係Nginx 做,改 server_name 同埋加 301 :
1 2 3 4 5 6 7 |
server_name hang321.net www.hang321.net if ($http_x_forwarded_proto = "http") { return 301 https://$server_name$request_uri; } ..... server_name hang321.net www.hang321.net |
Reference: