技术笔记 - My cloud dairy1: Deploy a Nginx server on ECS Ubuntu |我的云日记1: 在 ECS Ubuntu 上配置 Nginx 服务器

in #cn7 years ago (edited)

English version (Chinese version is in following part 中文版在第二部分)

Elastic Compute Service(ECS) is offered by almost all the popular cloud service providers. It can automatically decide how many cloud servers will be assigned to certain web page. In this blog, I will show you how to deploy a Nginx server on ECS (Ubuntu 16.04.2).

First step, you need a ECS server.

You can buy a ECS from Amazon, Tencent cloud or Aliyun. The purchase detail, please refer to the official guide of corresponding vender.

Second step, connect to that ECS server.

2.a. For Linux and Mac users, you can use Terminal with following command to connect ECS server:

ssh root@(ECS server IP address or domain);

2.b. For Windows users, you can download putty to connect ECS server。

In my case, I am a Mac user. I use Terminal for connecting to my ECS server:

Third step, download and install Nginx.

3.a. After you establish connection to your ECS server, create a new directory named "Nginx" in current path on your ECS server. And then enter that directory.

mkdir Nginx
cd Nginx

3.b. In directory "Nginx", create a new directory named "install", and enter that directory.

mkdir install
cd install

3.c. Download and install PGP key

wget "http://nginx.org/keys/nginx_signing.key"
sudo apt-key add nginx_signing.key

3.d. Modify sources list

3.d.1. Open /etc/apt/sources.list by VI
vi /etc/apt/sources.list

3.d.2. Append following contents to the end of file.

deb http://nginx.org/packages/ubuntu/ xenial nginx
deb-src http://nginx.org/packages/ubuntu/ xenial nginx


(Hints:VI insert command i,save and quit command :x)

3.e. Install Nginx

apt-get update
apt-get install nginx

If there is no errors in Terminal, that means Nginx is installed successfully.

Forth step, test.

4.a. Find Nginx related directories.

find / -name "nginx" -type d


If you have same result as mine, it means your Nginx server is installed correctly.

4.b. Start Nginx server

nginx -c /etc/nginx/nginx.conf

If it shows no errors in Terminal, your Nginx server starts successfully. Now you can type IP address of your ECS server in your web browser. If the welcome page is displayed, your Nginx server is deployed on ECS successfully.

If you have any doubts, feel free to leave me a message.

2017 Oct 24


中文版本

Elastic Compute Service(ECS) 弹性计算服务是现在各大云服务器提供商普遍提供的一种服务。它可以根据访问流量自动分配相应云端服务器的数量。今天我就来介绍下如何在没有任何编程基础的情况下,在ECS上配置Nginx服务器。这里我将给出的例子为服务器系统为 Ubuntu 16.04.2。如果您的服务器系统为其他操作系统可以参考 Nginx官方安装指南

首先,要有一台可以使用的ECS服务器。

你可以从Amazon,腾讯云或者阿里云这样的服务商处购买。购买方式请参照各服务商的购买指南。

第二步,用任意终端登录该ECS服务器。

2.a. Linux和Mac系统可以使用默认的Terminal终端,输入命令:

ssh root@(ECS服务器IP地址或者域名);

即可登录。

2.b. Windows系统可以下载 putty 并进行相应配置以登录ECS服务器。

比如我的Mac系统就使用默认的Terminal终端:

第三步,下载并安装 Nginx 相关文件。

3.a. 在成功用ssh与ECS服务器建立连接后,在ECS服务器当前目录下创建一个文件夹,命名为Nginx,并进入该文件夹。

mkdir Nginx
cd Nginx

3.b. 在Nginx目录中,创建一个名为install的文件夹,并进入该文件夹。

mkdir install
cd install

3.c. 下载 并安装PGP key

wget "http://nginx.org/keys/nginx_signing.key"
sudo apt-key add nginx_signing.key

3.d. 修改 sources list

3.d.1. 用 vi 打开文件 /etc/apt/sources.list
vi /etc/apt/sources.list

3.d.2. 将以下内容添加到文件末尾

deb http://nginx.org/packages/ubuntu/ xenial nginx
deb-src http://nginx.org/packages/ubuntu/ xenial nginx


(注:VI 插入命令 i,保存并退出 :x)

3.e. 安装 Nginx

apt-get update
apt-get install nginx

如果系统没有报错,nginx就安装完毕了。

第四步,调试

4.a. 检测Nginx文件

在服务器系统中搜索与nginx相关的文件夹。

find / -name "nginx" -type d


如果你的结果与我一样,说明与Nginx相关的文件已经安装就绪

4.b. 启动Nginx服务器

nginx -c /etc/nginx/nginx.conf

如果系统没有报错,说明Nginx服务器已经正常启动。现在可以打开浏览器并输入ECS服务器IP地址,如果成功显示Nginx欢迎页面说明Nginx服务已经成功安装并运行。

至此在 ECS Ubuntu 上配置 Nginx 服务器的内容已经全部介绍完毕,如果你有任何疑问可以给我留言。

2017年10月24日


后记

由于时间的关系,我平时很少写这种技术指南类型文章。写作这篇文章是源于我在 随笔 - 存量的副产品 让人走不开的枷锁 中写到的我准备把Wix上的网站移动到Wordpress。但我发现我之前在Wix上发布的内容很难一并移植到Wordpress。我考虑到如果有一天我离开Wordpress是不是也要面临一样的问题。索性干脆就直接自己租个服务器建个Wordpress server算了。建站的过程中发现网上很多教程要么省略掉了很关键的内容,要么就是许多提到的组件已经过期了,很不实用。所以决定自己写一篇,一来把整个建站的过程分享给更多的人,二来以后自己再建站的时候也好做个参考。很多人认为建立网站是件多么困难的事情,如果你读读我这篇文章,花点时间,你也能有属于你自己的网站。


以上内容由steemit作者 @breathewind 原创发布。
All the contents above are published by Steemit author @breathewind.

转载请注明出处。
Please indicate the source when you reblog or reuse.

如果您对我的内容感兴趣,不妨试试这些文章:
If you like my post, the following posts may be interested for you as well:

游记 - 意大利阿尔巴松露节之旅 | A trip on Alba White Truffle Fair
瞎想 - 如果世界不是客观的而是主观的呢?
[Solution in Qt] Mathematics × Programming Competition #8 [Qt解答] 數學 × 程式編寫比賽 (第八回)

谢谢阅读 !
Thanks for your reading !

欢迎您我对我点赞,评论或者订阅 @breathewind
Please feel free to upvote, comment and follow me @breathewind


Sort:  

支持一下,其实我有个想法是做一个基于steem的blog,以前有人做过,但没有好用的。你有时间可以尝试一下,你的所有文章都存在在区块链上,用户可以给你点赞,获取收益,而且你还可以在你blog上加广告。成本也很小,就是维护一个前端,放在github就行,只需要自己买一个域名。

研究明白后,最好能有个通用的教程。不限于搭博客,可以扩展其他形式。

我也有这个想法。我想拿自己的网站当个试验,看能不能写出一个好用的前端,以后可以推而广之。

Coin Marketplace

STEEM 0.20
TRX 0.13
JST 0.030
BTC 61620.03
ETH 3394.18
USDT 1.00
SBD 2.50