Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
在 Google Cloud Platform 架設你的網站伺服器並撰寫 Node.js 應用程式
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
chph
September 01, 2017
Technology
710
0
Share
在 Google Cloud Platform 架設你的網站伺服器並撰寫 Node.js 應用程式
afu @ PIXNET 前端團隊 2017.09.01
chph
September 01, 2017
More Decks by chph
See All by chph
Chrome Dev Tools 基礎技巧
chph
0
98
DevOpsDays Taipei 2017 敏捷思維分享
chph
0
120
Intro to Progressive Web Apps
chph
1
71
淺談 Gzip
chph
0
130
Install WordPress on Linode
chph
0
170
Introduction Infrastructure - Linode 入門
chph
0
230
高速傳愛~三小時進化 PWA
chph
0
300
Optimize JavaScript execution and parse time using optimize-js
chph
0
160
Modern Web 2016 議程分享: 網站自動化測試 - 以 PIXNET 搜尋 & 美妝口碑大賞為例
chph
0
130
Other Decks in Technology
See All in Technology
基礎から解説!Icebergで紐解くSnowflake×Databricks連携の現在地
cm_yasuhara
0
310
大規模環境でどのように監視を実現する?
yuobayashi
1
140
Pythonでベイズモデリング
soogie
0
180
Harnessing the Power of Mocks and Stubs in PHPUnit / #laravellivejp
asumikam
0
560
AI時代に求められる思考のパラダイムシフト
nrinetcom
PRO
1
150
「使われるデータ基盤」を目指してデータアナリストとワークショップをやった話
jackojacko_
2
850
AI時代に改めて考える、ドメイン駆動設計 - モデリングが「AIへの共通言語」になる
littlehands
7
2.3k
【禁断】Obsidianの第二の脳に「知の巨人」と呼ばれた師匠の脳をロードしてみた
nagatsu
0
6.5k
情シスがMCP環境導入時に打ちのめされる認可の崖
oidfj
0
450
CARTA HOLDINGS エンジニア向け 採用ピッチ資料 / CARTA-GUIDE-for-Engineers
carta_engineering
0
47k
TSKaigi 2026 - Auth.jsからBetter Authへの 移行に見る「型とランタイム」の 設計思想の変化
teamlab
PRO
1
260
JJUG CCC 2026 Spring AI時代の開発こそ標準化を武器に! ― 方式・プロセス・プラットフォームの標準化
s27watanabe
1
270
Featured
See All Featured
Joys of Absence: A Defence of Solitary Play
codingconduct
1
370
The World Runs on Bad Software
bkeepers
PRO
72
12k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
260
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
230
Optimising Largest Contentful Paint
csswizardry
37
3.7k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.2k
The Spectacular Lies of Maps
axbom
PRO
1
760
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
140
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Transcript
在 Google Cloud Platform 架設 你的網站伺服器並撰寫 Node.js 應用程式 PIXNET Travel
會議室 | 2017.09.01 afu @ 研發中心前端組 @afutseng
Agenda 免費註冊 GCP 建立專案與新增虛擬機器 (VM) 安裝 Apache & 你的慣用軟體 示範安裝
Node.js 8 & PHP 7 撰寫 Node.js Hello World 程式 將 Apache 作為代理伺服器轉送請求給 Node.js 應用程式
申請免費試用
None
建立專案
新增 SSH 金鑰 • 點開左上漢堡 Bar • Compute Engine ->
中繼資料 • cat ~/.ssh/id_rsa.pub P.S. 如無該檔案請用 ssh-keygen 指令產生新的金鑰
新增虛擬機器 • Compute Engine / VM 執行個體 • 機器類型:微型 (micro)
/ 1 vCPU / 0.6 GB RAM *免費* (仍顯示每月 $4.28 USD 預估費用) • 勾選允許 HTTP & HTTPS 流量
使用終端機透過 ssh 連上剛開好的 VM $ ssh
[email protected]
更新軟體 $ sudo apt-get update # 抓取新的軟體版本
安裝網站伺服器 - Apache 2.4 $ sudo apt-get install apache2 安裝完成後可用
apache2 -v 指令查詢版本資訊
啟動網站伺服器 $ sudo service apache2 restart # 重開 server •
start - 啟動 apache web server • stop - 停止 apache web server
瀏覽器連上你的機器 IP 應可看到 Apache 預設首頁
練習安裝你的慣用軟體 • git / tmux / screen / mosh •
偏好的 Shell (例如 zsh) & VIM 設定 • 偏好的程式語言 (PHP, Node.js, Python, Ruby, etc.)
示範安裝 Node.js v8.4.0 curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash
- sudo apt-get install -y nodejs 安裝完成後可用 node -v 指令查詢版本資訊 其他作業系統平台可參考 :https://nodejs.org/en/download/package-manager/
示範安裝 PHP 7.0 sudo apt-get install -y php7.0 安裝完成後可用 php
-v 指令查詢版本資訊
安裝 Apache PHP 7 的模組 (Optional) 注意,必須先安裝 Apache sudo apt-get
install -y libapache2-mod-php7.0
撰寫 Node.js Hello World 伺服器程式 const http = require("http"); const
server = http.createServer((request, response) => { response.writeHead(200, { "Content-Type" : "text/plain"}); response.write( "hello world~" ); response.end(); }); server.listen(3000); console.log("Server is listening" );
以 Apache 作為代理伺服器轉送請求 應用情境:80 port 有跑 PHP 或其他語言,將 Apache 作為
Proxy 角色依需求 轉送請求到跑在其他 port 的 web server sudo a2enmod proxy sudo a2enmod proxy_http 範例:編輯預設 Apache config sudo vim /etc/apache2/sites-enabled/000-default.conf
把 /nodejs 路由請求轉送給 3000 port 處理 <VirtualHost *:80> # 原有設定,
略 ProxyPass /nodejs http://localhost:3000/ </VirtualHost > *記得重開 Apache
None
其他方案:使用 PM2 管理 node processes sudo npm install pm2 -g
pm2 start server.js pm2 list|restart|stop|delete http://pm2.keymetrics.io/
Thanks
None
None