在ECS實例上部署Nginx,編輯HTML頁面,使訪問ECS01時返回一個標題為“Welcome to ELB test page one!”的頁面,訪問ECS02時返回一個標題為“Welcome to ELB test page two!”的頁面。
- 登錄彈性云主機。
- 安裝nginx。
a) 使用wget命令,下載對應當前操作系統版本的Nginx安裝包。此處以CentOS 7.6版本的操作系統為例。
wget //nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
b) 執行以下命令,建立Nginx的yum倉庫。此處以CentOS 7.6版本的操作系統為例。
rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
c) 執行以下命令,安裝Nginx。
yum -y install nginx
d) 執行以下命令,啟動Nginx并設置開機啟動。
systemctl start nginx
systemctl enable nginx
e) 在任意終端使用瀏覽器訪問“//ECS的公網IP地址”,顯示如下頁面,說明nginx安裝成功。

- 修改ECS實例ECS01的html頁面。
Nginx的默認根目錄是“/usr/share/nginx/html”,修改“index.html”頁面,用來標識到ECS01的訪問。
a) 執行以下命令打開文件“index.html”。
vim /usr/share/nginx/html/index.html
b) 按i鍵進入編輯模式。
c) 修改打開的“index.html”文件。
修改文件內容,涉及內容修改部分如下所示:
...
<body>
<h1>Welcome to <strong>ELB</strong> test page one!</h1>
<div class="content">
<p>This page is used to test the <strong>ELB</strong>!</p>
<div class="alert">
<h2>ELB01</h2>
<div class="content">
<p><strong>ELB test (page one)!</strong></p>
<p><strong>ELB test (page one)!</strong></p>
<p><strong>ELB test (page one)!</strong></p>
</div>
</div>
</div>
</body>
d) 按Esc鍵退出編輯模式,并輸入:wq保存后退出。
- 修改ECS實例ECS02的html頁面。
Nginx的默認根目錄是“/usr/share/nginx/html”,修改“index.html”頁面,用來標識到ECS02的訪問。
a) 執行以下命令打開文件“index.html”。
vim /usr/share/nginx/html/index.html
b) 按i鍵進入編輯模式。
c) 修改打開的“index.html”文件。
修改文件內容,涉及內容修改部分如下所示:
...
<body>
<h1>Welcome to <strong>ELB</strong> test page two!</h1>
<div class="content">
<p>This page is used to test the <strong>ELB</strong>!</p>
<div class="alert">
<h2>ELB02</h2>
<div class="content">
<p><strong>ELB test (page two)!</strong></p>
<p><strong>ELB test (page two)!</strong></p>
<p><strong>ELB test (page two)!</strong></p>
</div>
</div>
</div>
</body>
d) 按Esc鍵退出編輯模式,并輸入:wq保存后退出。
- 使用瀏覽器分別訪問“//ECS01的公網IP地址”和“//ECS02的公網IP地址”,驗證nginx服務。
如果頁面顯示修改后的html頁面,說明nginx部署成功。

