nginx子域名配置_在具有实时域,子域,Nginx,带有免费SSL和Git的Cloudflare的AWS EC2实例上部署单个/多个Node.js应用程序。

本文档介绍了如何在AWS EC2实例上,结合Cloudflare的免费SSL服务,利用Nginx配置子域名,以部署单个或多个Node.js应用程序。通过Nginx作为反向代理,可以实现HTTPS和子域名的设置。
摘要由CSDN通过智能技术生成

nginx子域名配置

介绍 (Introduction)

Node.js is an open-source, cross-platform, JavaScript runtime environment that executes JavaScript code outside a web browser. Node.js is built on open-source V8 JavaScript engine for easily building fast and scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

Node.js 是一个开放源代码,跨平台JavaScript运行时环境,可在Web浏览器外部执行JavaScript代码。 Node.js构建在开源V8 JavaScript引擎上 ,可轻松构建快速且可扩展的网络应用程序。 Node.js使用事件驱动的非阻塞I / O模型,使其轻巧高效,非常适合跨分布式设备运行的数据密集型实时应用程序。

NGINX is open-source software for web serving, reverse proxying, caching, load balancing, media streaming, and more. In addition to its HTTP server capabilities, NGINX can also function as a proxy server for email (IMAP, POP3, and SMTP) and a reverse proxy and load balancer for HTTP, TCP, and UDP servers.

NGINX是用于Web服务,反向代理,缓存,负载平衡,媒体流等的开源软件。 除了HTTP服务器功能之外,NGINX还可以充当电子邮件的代理服务器(IMAP,POP3和SMTP)以及HTTP,TCP和UDP服务器的反向代理和负载平衡器。

AWS is a platform that offers flexible, reliable, scalable, easy-to-use and cost-effective cloud computing solutions and is offered by Amazon. The platform is developed with a combination of infrastructure as a service (IaaS), platform as a service (PaaS) and packaged software as a service (SaaS) offerings.

AWS 是一个平台,由亚马逊提供,可提供灵活,可靠,可扩展,易于使用且具有成本效益的云计算解决方案。 该平台是结合基础架构即服务(IaaS),平台即服务(PaaS)和打包软件即服务(SaaS)产品的组合而开发的。

EC2 or Elastic Compute Cloud is a web service that provides secure, resizable compute capacity in the cloud. Amazon EC2’s simple web service interface allows you to obtain and configure capacity with minimal friction. It provides you with complete control of your computing resources and lets you run on Amazon’s proven computing environment.

EC2 或Elastic Compute Cloud是一项Web服务,可在云中提供安全的,可调整大小的计算能力。 Amazon EC2的简单Web服务界面使您能够以最小的摩擦获得和配置容量。 它为您提供了对计算资源的完全控制,并允许您在Amazon成熟的计算环境中运行。

Cloudflare is an American web-infrastructure and website-security company, providing content-delivery-network services, DDoS mitigation, Internet security, and distributed domain-name-server services.

云耀斑 是一家美国的网络基础设施和网站安全公司,提供内容交付网络服务,DDoS缓解,互联网安全和分布式域名服务器服务。

Git is a distributed version control system for tracking changes in source code during software development.

Git是一个分布式版本控制系统,用于在软件开发过程中跟踪源代码的更改。

我们将要实施的 (What we are going to implement)

  1. Create an AWS account

    创建一个AWS账户
  2. Launch an Ubuntu EC2 instance

    启动Ubuntu EC2实例
  3. SSH into our instance

    SSH进入我们的实例
  4. Install Node.js and Git

    安装Node.js和Git
  5. Clone repository from GitHub

    从GitHub克隆存储库
  6. Run the node.js app

    运行node.js应用
  7. Open different ports for the node instances

    打开节点实例的不同端口
  8. Make the app running using PM2

    使用PM2使应用程序运行
  9. Configure Nginx for single and multiple node.js apps

    为单个和多个node.js应用程序配置Nginx
  10. Configure Nginx to autostart whenever instance will be rebooted

    将Nginx配置为每当实例重启时自动启动
  11. Purchase a domain from Godaddy, Namecheap, etc.

    从Godaddy,Namecheap等购买域名。
  12. Configure domain name for our server

    为我们的服务器配置域名
  13. Configure subdomains for our server

    为我们的服务器配置子域
  14. Setup SSL with Cloudflare

    使用Cloudflare设置SSL

创建一个AWS账户 (Create an AWS Account)

We are using AWS EC2 server for hosting our multiple node.js apps. So, It is must to have an AWS account. Let’s start and create if you are not having one. For new users, there is an offer of 750 hours free per month up to a year. You must have a credit/debit card before start registering.

我们正在使用AWS EC2服务器托管我们的多个node.js应用程序 。 因此,必须拥有一个AWS账户。 如果您没有一个,让我们开始创建。 对于新用户, 每年最多提供750个小时的免费服务 。 开始注册之前,您必须具有信用卡/借记卡。

Note: If you are already having an AWS account then you can skip this step and just login to your instance.

注意:如果您已经拥有一个AWS账户,则可以跳过此步骤,仅登录到您的实例。

  1. Open AWS and Click on Create an AWS account.

    打开AWS 然后单击Create a AWS account

  2. Fill all the required fields and click on Continue.

    填写所有必填字段,然后单击继续。

3. Fill out all the contact information.

3.填写所有联系信息。

Image for post

4. After this, you’ll be asked for your Credit/Debit card details. Fill them correctly and AWS will verify your card by making a deducting a little amount.

4.之后,系统会要求您提供信用卡/借记卡详细信息。 正确填写它们,AWS会扣除一些费用来验证您的卡。

Image for post

5. After this, you will be asked to choose a support plan. Choose a basic plan which is free or choose another one if you want extra features.

5.之后,将要求您选择一个支持计划。 选择一个免费的基本计划 ,如果需要其他功能,请选择另一个计划

Image for post

6. Now you’ve successfully created your account. Now simply log in to the AWS console.

6.现在,您已经成功创建了您的帐户。 现在,只需登录AWS控制台

启动Ubuntu EC2实例 (Launch an Ubuntu EC2 instance)

Now to host our node.js apps we need an EC2 virtual machine or instance. So let’s get started to make our first EC2 instance up.

现在要托管我们的node.js应用程序,我们需要一个EC2虚拟机或实例 。 因此,让我们开始构建第一个EC2实例。

  1. Log in to AWS and click on the Sign in to the Console. Open your AWS console.

    登录到AWS并单击“ 登录到控制台” 。 打开您的AWS控制台。

2. Click on EC2 in the All Services section.

2.单击“所有服务”部分中的EC2

Image for post

3. You will see a screen like below. Where all the currently running instances can be shown. Now click on the Running instances.

3.您将看到如下屏幕。 可以显示所有当前正在运行的实例的位置。 现在单击“正在运行的实例”

Note: Right now I am having no instances running so it is displaying 0 there.

注意:目前我没有任何实例在运行,因此该实例显示为0。

Image for post

4. After clicking on Running Instances you’ll see a Launch Instance button there.

4.点击后 运行实例时,您将在其中看到启动实例按钮。

Image for post

5. Now, click on the Launch Instance button. After clicking you will see a page like this which shows the type of OS with the config you want in your machine e.i. We are going to use a Ubuntu Server 20.04 LTS 64-bit (x86).

5.现在,单击启动实例按钮。 单击后,您将看到一个类似这样的页面,其中显示了您要在计算机中使用所需配置的操作系统类型ei我们将使用Ubuntu Server 20.04 LTS 64位(x86)

Image for post

6. Now, click on Select button and on the next screen you’ll be asked to select an instance type. We are going to use t2.micro as it is eligible for availing free tier. Click on Review and Launch.

6.现在,单击“ 选择”按钮,然后在下一个屏幕上将要求您选择实例类型。 我们将使用t2.micro,因为它可以使用免费套餐 。 单击查看并启动

Image for post

After clicking, all the information of the instance will appear.

单击后,将显示该实例的所有信息。

Image for post

7. Now, click on Launch. A popup will appear asking for a key. Basically, these keys will allow you to SSH into your instance ( will discuss in next step). You can choose existing key pairs if you have already one created before else you can create a new.

7.现在,单击启动 。 将会出现一个弹出窗口,要求您输入密钥。 基本上,这些密钥将使您可以SSH进入实例(将在下一步中讨论)。 如果已经创建了一个密钥对,则可以选择现有的密钥对,否则可以创建一个新的密钥对。

Image for post

Click on the dropdown displaying Choose an existing pair and click on Create a new key pair. Enter a key pair name. After writing the name click on Download key pair in the popup and store it on your PC where you can access it easily later on. Now Launch Instances will get enabled.

单击显示“选择现有对”的下拉列表,然后单击“ 创建新密钥对” 。 输入密钥对名称。 输入名称后,在弹出窗口中单击“ 下载密钥对” ,然后将其存储在您的PC上,以后可以轻松访问它。 现在,启动实例将被启用。

Note: Keep your key in a secure place and don’t share your key with someone else not working with you on this.

注意:请将您的钥匙放在安全的地方,不要与其他未与您合作的人共享您的钥匙。

Your key must not be publicly viewable for SSH to work. Use the below command if needed. Always provide a correct path for the key. In below example, I am in the same directory in which my pen file or my key is present.

您的密钥不得公开可见,SSH才能正常工作。 如果需要,请使用以下命令。 始终为钥匙提供正确的路径。 在下面的示例中,我位于笔文件或密钥所在的目录中。

chmod 400 path-for-key-hereFor Example:chmod 400 ./node-key.pem

8. Click on Launch Instances wait for few seconds and you’re done when this screen appears.

8.单击启动实例等待几秒钟,当此屏幕出现时,您完成操作。

Image for post

9. Now click on the instance id ( In my case i-0c01d1c3a24827c5e ) which appears in the green block above. You will be redirected to the instances page and now you can see your instance is up and running.

9.现在,单击实例ID(在我的情况下为i-0c01d1c3a24827c5e ),该实例ID显示在上方的绿色块中。 您将被重定向到实例页面,现在您可以看到实例已启动并正在运行

Image for post

Hurray!! You started an AWS machine ( virtual machine ).

欢呼!! 您启动了一个AWS机器(虚拟机)。

SSH进入我们的实例 (SSH into our instance)

SSH means Secure Shell. The purpose of doing SSH to our instance is we want to access our server through a secure manner which you can access by using your terminal/cmd or using other Softwares like Putty. Now, depending upon your Operating System you can access your server in different manners.

SSH表示安全外壳。 对我们的实例执行SSH的目的是我们希望通过一种安全的方式访问我们的服务器,您可以使用终端/ cmd或使用其他软件(例如Putty)来访问它。 现在,根据您的操作系统,您可以以不同的方式访问服务器。

For Windows You can use Putty, etc.

对于Windows,您可以使用Putty等。

For Mac / Linux

对于Mac / Linux

  • Open your terminal

    打开你的终端
  • Go to AWS EC2 instances section and choose any instance.

    转到AWS EC2实例部分,然后选择任何实例。
Image for post
  • Copy the Public IP and write the below command in your terminal with your instance public IP which you have copied.

    复制公共IP,并使用已复制的实例公共IP在您的终端中写入以下命令。

Note: Please make sure your private key location is correct in your local PC. Which you have downloaded in the previous step. In below example, I am in the same directory in which the node-key.pem is present.

注意:请确保您的私钥位置在本地PC中正确。 您已在上一步中下载了该文件。 在下面的示例中,我位于存在node-key.pem的目录中。

ssh -i "private-key-location" ubuntu@public-ipFor examplessh -i "./node-key.pem" ubuntu@ec2-54-158-217-172.compute-1.amazonaws.com

Hit enter, Now the below screen will appear which means everything is successfully verified. Provide yes if prompted to add this public server URL to your local records.

按回车键,现在将出现以下屏幕,这意味着所有内容均已成功验证。 如果系统提示您将此公用服务器URL添加到本地记录中,请提供yes。

Image for post

安装Node.js和Git (Install Node.js and Git)

Installing Node :

安装节点:

To run a Node.js app we require Node.js to be installed on our instance. So we will install all the required dependencies which can be used to install Node.js on our ubuntu instance.

运行Node.js应用 我们需要在实例上安装Node.js。 因此,我们将安装所有必需的依赖项,这些依赖项可用于在我们的ubuntu实例上安装Node.js。

There are many ways to install node on our instance:

有多种方法可以在我们的实例上安装节点:

Installing Node.js and npm from NodeSource

从NodeSource安装Node.js和npm

First, of all Enable the NodeSource repository by running the following curl command as a sudo user on your instance using the terminal:

首先,通过使用终端在您的实例上以sudo用户身份运行以下curl命令来启用NodeSource存储库:

$ sudo curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

Note: If you want to install some another version, of Node.js. For example, 14.x, just change thesetup_12.x with setup_14.x

注意:如果要安装其他版本的Node.js。 例如,14.x,只需将setup_12.x更改为setup_14.x

Image for post

Once the NodeSource repository gets enabled, You can install Node.js and npm on your instance by typing:

启用NodeSource存储库后,可以通过键入以下内容在实例上安装Node.js和npm:

$ sudo apt install nodejs -y

The Node.js package will get installed which contains both the node and npm binaries.

将安装包含nodenpm二进制文件的Node.js软件包。

Now, Verify that the Node.js and npm were successfully installed by printing their versions:

现在,通过打印它们的版本来验证Node.js和npm是否已成功安装:

$ node --versionOutput: v12.18.2$ npm --versionOutput: 6.14.5
Image for post

Installing Git :

安装Git:

To get our code on our EC2 Instance we need git. So, the below steps will define how to install Git on our EC2 instance.

要在我们的EC2实例上获取代码,我们需要git 。 因此,以下步骤将定义如何在我们的EC2实例上安装Git。

To refresh all the packages run

刷新所有运行的包

$ sudo apt update -y
Image for post

Then to install git run

然后安装git运行

$ sudo apt install git
Image for post

从GitHub克隆存储库 (Clone repository from GitHub)

Now, we have Node.js and Git installed on our EC2 Instance. Now, we need the codebase on our ec2 instance. So, we will clone our repositories using the username and password from services like Github, Bitbucket, Gitlab, etc. I am using Github here.

现在,我们在EC2实例上安装了Node.js和Git。 现在,我们需要ec2实例上的代码库。 因此,我们将使用Github,Bitbucket,Gitlab等服务中的用户名和密码来克隆存储库。 我在这里使用Github。

  1. Go to Github.

    转到Github

  2. Navigate to your repository which you want to clone.

    导航到要克隆的存储库

  3. Click on Code.

    单击代码

Image for post

4. Copy the https URL from Github.

4.从Github复制https URL。

5. SSH into your EC2 Instance

5. SSH进入您的EC2实例

6. Write the following command there and paste your repository URL.

6.在此编写以下命令,然后粘贴您的存储库URL。

$ git clone https://git-url-hereFor example:$ git clone https://github.com/geekyoperand/nodejs-basic.git

7. Now, if your repository is private the terminal will prompt for your GitHub username and password. Provide the username and password of your GitHub.

7.现在,如果您的存储库是私有的,则终端将提示您输入GitHub用户名和密码。 提供您的GitHub的用户名和密码。

Image for post

!! Hurray, we just cloned our repository on our EC2 instance.

!! 欢呼,我们只是在我们的EC2实例上克隆了我们的存储库。

运行node.js应用 (Run the node.js app)

Now, You have Git, Node.js and our repository all on our EC2 instance. It’s time to run our node.js app on our live server.

现在,您在我们的EC2实例上拥有Git,Node.js和我们的存储库。 现在该在实时服务器上运行node.js应用程序了。

  1. Navigate into our project folder on our EC2 instance using SSH.

    使用SSH导航到EC2实例上的项目文件夹。
$ cd folder-nameFor example$ cd nodejs-basic

2. Run the below command to install all the dependencies for your project

2.运行以下命令以安装项目的所有依赖项

$ npm install

3. Start your app using below commands or start it in the way you have set up your app that how it starts using which particular command which has been already defined in the package.json.

3.使用以下命令启动您的应用程序,或者以您设置应用程序的方式启动它,并使用package.json中已定义的特定命令启动应用程序。

In our project, I have defined the command as start. So, I will run

在我们的项目中,我已将命令定义为start 。 所以我会跑

$ npm run start
Image for post

It will start your project on a port number that is defined by you already.

它将在您已经定义的端口号上启动您的项目。

Note: Please copy or remember port no’s of each node app you run on a particular EC2 instance. It will be required in the next step.

注意:请复制或记住您在特定EC2实例上运行的每个节点应用程序的端口号。 下一步将需要它。

Important: Similarly, you can clone multiple repositories or multiple node projects and start them by installing node_modules on your single EC2 instance. Make sure that the port of each project cloned on the same EC2 instance must be different.

重要说明:同样,您可以克隆多个存储库或多个节点项目,并通过在单个EC2实例上安装node_modules来启动它们。 确保在同一EC2实例上克隆的每个项目的端口必须不同。

For example, I am going to host two node apps on the same EC2 instance. So, I cloned both from GitHub, installed dependencies, started them by running a specific command i.e. npm run start.

例如,我要在同一EC2实例上托管两个节点应用程序。 因此,我从GitHub克隆了两个,安装了依赖项,并通过运行特定命令(即npm run start)启动了它们。

The port of my first app is 3000 and the second app is 3001.

我的第一个应用程序的端口是3000,第二个应用程序的端口是3001。

打开节点实例的不同端口 (Open different ports for the node instances)

Now, It’s time to make your project public by opening ports. First of all, just go into the AWS console. In EC2 section select your current instance and copy the public DNS of your instance.

现在,是时候开放港口来公开您的项目了。 首先,只需进入AWS控制台。 在EC2部分中,选择您的当前实例,然后复制您实例的公共DNS。

Image for post

It is ec2–54–158–217–172.compute-1.amazonaws.com in my case. Now, go to your browser and paste the DNS in the top search panel with the port number.

就我而言,它是ec2–54–158–217–172.compute-1.amazonaws.com。 现在,转到浏览器,将DNS粘贴在顶部搜索面板中,并显示端口号。

For example:

例如:

http://ec2-54-158-217-172.compute-1.amazonaws.com:3000

Press Enter. Now, you can see that It is giving us Connection Timed Out message. Why? 🤔

按Enter键。 现在,您可以看到它给了我们连接超时消息。 为什么? 🤔

Image for post

It is because we haven’t opened the current port for access to the public. Now, It’s time to give the public access to our port which is 3000 for now.

这是因为我们尚未开放当前端口供公众使用。 现在,是时候让公众进入我们的港口了(目前为3000)。

Let’s start without wasting any time.

让我们开始时不要浪费任何时间。

  1. In the AWS management console, Go to the EC2 section and go to the Security Groups section.

    在AWS管理控制台中,转到EC2部分,然后转到安全组部分。

Image for post
  1. In that select your instance which is launch-wizard-1 in our case. You can match this id to your instance in case you are having multiple instances.

    在这种情况下,请选择您的实例,在本例中为launch-wizard-1。 如果您有多个实例,可以将此ID与实例匹配。
Image for post
  1. Now click on Edit Inbound rules.

    现在,单击“ 编辑入站规则”

Image for post

Now click on Add Ruleselect Custom TCP Rule and add Port range of your node.js app ( basically we need to add a port here ) which is 3000 in our case

现在单击Add Rule选择Custom TCP Rule并添加node.js应用程序的端口范围(基本上我们需要在此处添加端口),在本例中为3000

Select custom in source and add 0.0.0.0/0 which means from which IP addresses you can access this port.Now, click on Save rules.

在来源中选择自定义,然后添加0.0.0.0/0,这意味着您可以从哪个IP地址访问此端口。现在,点击保存规则

Image for post

Note: Similarly, add all the ports of your apps that you want to run on your current EC2 instance only if you are setting up multiple node.js apps. So, I am adding one more port 3001 as we have one more node.js app which runs on PORT 3001.

注意:同样,仅当要设置多个node.js应用程序时,才添加要在当前EC2实例上运行的应用程序的所有端口。 因此,我要添加一个端口3001,因为我们还有一个在PORT 3001上运行的node.js应用程序。

Image for post
  1. You can also notice that we have port 22 already opened for public. Through which you are doing SSH in your instance using your terminal.

    您还可以注意到我们已经开放了22端口供公众使用。 通过它,您可以使用终端在实例中执行SSH。
  2. Now, Go to your browser and open that URL again which we previously used. You can see it is working now and is displaying your node.js app. make sure in ssh terminal the server is still running.

    现在,转到浏览器并再次打开我们先前使用的URL。 您可以看到它现在正在运行,并且正在显示您的node.js应用程序。 确保在ssh终端中服务器仍在运行。
Image for post

Hurray!!, It is working now.

万岁!!,它正在工作。

But the URL seems to be very awkward. So, we are going to change it near the next steps.

但是网址似乎很尴尬。 因此,我们将在下一步附近进行更改。

使用PM2使应用程序运行 (Make the app running using PM2)

You can notice that until your EC2 SSH terminal is connected. The app is running but the moment you close the server terminal your app gets down that is because your node process also gets stopped. So to prevent this we are going to use PM2 ( production process manager ). So, As the name predicts, it is used to manage all the processes in a production environment, So if we close our SSH session or terminal the process started by PM2 will not get stopped until we manually stop the process.

您会注意到,直到连接了EC2 SSH终端。 该应用程序正在运行,但是当您关闭服务器终端时,您的应用程序关闭了,这是因为您的节点进程也被停止了。 因此,为了防止这种情况,我们将使用PM2(生产过程管理器)。 因此,顾名思义,它用于管理生产环境中的所有流程。因此,如果我们关闭SSH会话或终端,则直到手动停止流程后,PM2所启动的流程才会停止。

So, let’s install PM2 on our EC2 instance :

因此,让我们在EC2实例上安装PM2:

$ sudo npm install -g pm2

Now, we have successfully installed pm2. It’s time to run our node app with pm2. In my case, my app start script is written in package.json which is npm run start. If your app starting script is in package.json then write the below command and hit enter.

现在,我们已经成功安装了pm2。 现在该使用pm2运行我们的节点应用程序了。 就我而言,我的应用启动脚本是在package.json中编写的,它是npm run start。 如果您的应用程序启动脚本位于package.json中,请编写以下命令,然后按Enter。

$ pm2 start npm -- OR$ pm2 start npm --name "name_the_process_anything_you_want" -- "script_of_the_process_defined_in_package.json"For example$ pm2 start npm -- startOR$ pm2 start npm --name my-first-node-app -- start
Image for post

You can also try these below commands if your app has some other configuration.

如果您的应用具有其他配置,也可以尝试以下命令。

$ 
$ pm2 start app.js ( if you are using node app.js command )
$ pm2 start ./bin/www ( if you are using node ./bin/www command )

Now check the URL. Its working right. Now close your terminal and check the URL again. It’s still working. Hurray!! we just started our node server with PM2.

现在检查URL。 它的工作权利。 现在关闭终端,然后再次检查URL。 它仍在工作。 欢呼!! 我们刚刚从PM2启动了节点服务器。

Important: Similarly, you can start several processes by following the same steps for different node projects. I am starting two pm2 processes for two different node projects which are running on port 3000 and 3001.

重要说明:同样,您可以通过针对不同的节点项目执行相同的步骤来启动多个过程。 我正在为端口3000和3001上运行的两个不同的节点项目启动两个pm2进程。

Now, what if our EC2 machine or EC2 instance restarts. Execute the below command in your ssh terminal to automatically restart the pm2 processes when the instance reboots.

现在,如果我们的EC2机器或EC2实例重新启动该怎么办。 在实例重启时,在ssh终端中执行以下命令以自动重启pm2进程。

$ pm2 startup
Image for post

After running this command you will get a script on the output screen. Run this script in your terminal window after copying.

运行此命令后,您将在输出屏幕上获得一个脚本。 复制后在终端窗口中运行此脚本。

For example:$ sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u ubuntu — hp /home/ubuntu

Now, we need to save all the currently running processes. So that it can be restart after PM2 restarts. Now, to save all the currently running processes, run the following command:

现在,我们需要保存所有当前正在运行的进程。 这样可以在PM2重新启动后重新启动。 现在,要保存所有当前正在运行的进程,请运行以下命令:

$ pm2 save

Now, whenever your instance reboots the pm2 processes will also restart.

现在,每当您的实例重新启动时,pm2进程也将重新启动。

Image for post

为单个和多个node.js应用程序配置Nginx (Configure Nginx for single and multiple node.js apps)

You can notice our URL has a port number with it but normally the URLs don’t have a port number with their URL’s. Usually, all the web apps or sites are generally served on port 80 ( used for HTTP requests ) which our browsers assume it by default. Whereas our node apps are running on publicly open ports which are 3000 and 3001 in our case. Which is not a good idea because we are directly exposing the or node app to the internet traffic or our audience. We are also reducing our node app performance by not taking advantages of load balancing or server static content efficiently. So how to remove that port number and manage the performance of our EC2 machine.

您会注意到我们的URL带有一个端口号,但通常这些URL没有带有其URL的端口号。 通常,所有Web应用程序或站点通常都在端口80(用于HTTP请求)上提供服务,我们的浏览器默认将其用作端口80。 而我们的节点应用程序运行在公共开放端口上(在本例中为3000和3001)。 这不是一个好主意,因为我们直接将or节点应用程序暴露给互联网流量或受众。 我们还没有充分利用负载平衡或服务器静态内容的优势,从而降低了节点应用程序的性能。 因此,如何删除该端口号并管理我们的EC2计算机的性能。

A simple and a better approach to manage this all is to use NGINX as a reverse proxy server in front of all our application servers or node servers. Using NGINX we will get these features for improving our performance.

一个简单而更好的方法是使用NGINX作为我们所有应用程序服务器或节点服务器之前的反向代理服务器。 使用NGINX,我们将获得这些功能来改善性能。

  1. Implement a reverse proxy server

    实施反向代理服务器

  2. Cache static files

    缓存静态文件

  3. Load balance traffic across multiple servers

    跨多台服务器负载均衡流量

  4. Proxy WebSocket connections

    代理WebSocket连接

  5. Implement SSL/TLS and HTTP/2

    实施SSL / TLS和HTTP / 2

NGINX will act as an efficient web server with all these features listed above who is routing multiple requests on port 80 to all different application servers or node servers based on the domain.

NGINX将充当上面列出的所有这些功能的高效Web服务器,它将基于端口将端口80上的多个请求路由到所有不同的应用程序服务器或节点服务器。

So, to get all these features. Let’s set up NGINX in front of our application servers.

因此,要获得所有这些功能。 让我们在应用服务器之前设置NGINX。

1. SSH into your instance and install NGINX using below command.

1. SSH进入您的实例,并使用以下命令安装NGINX。

$ sudo apt install nginx -y

after installation, you can check your version of Nginx by typing nginx -v .

安装后,您可以通过键入nginx -v来检查您的Nginx版本。

2. Now you have to open port 80 for the public because all the HTTP requests from the browser by default go to port 80 when we write our URL without any port.3. Open port 80 by following the same steps mentioned in Step 7.

2.现在您必须为公众开放端口80,因为默认情况下,当我们编写不带任何端口的URL时,来自浏览器的所有HTTP请求默认都会到达端口80。3。 按照步骤7中提到的相同步骤打开端口80。

Image for post

Now your port 80 is opened for public access.

现在,您的端口80已打开以供公共访问。

Now, copy the public DNS or the public IP of your EC2 instance and simply paste it in the browser without any port. Like this

现在,复制您的EC2实例的公用DNS或公用IP,然后将其粘贴到浏览器中,而无需任何端口。 像这样

54.158.217.172orec2-54-158-217-172.compute-1.amazonaws.com
Image for post

Note: IP and DNS address is always unique for an instance. So, make sure you are using DNS address or IP of your instance.Now, you’ll see an NGINX welcome page.

注意:IP和DNS地址对于实例始终是唯一的。 因此,请确保您使用的是实例的DNS地址或IP。 现在,您将看到一个NGINX欢迎页面。

Image for post

What we have done till now is we are not moving our app to port 80. Our all applications either it is one or many on a particular ec2 machine will run on their ports i.e. 3000 and 3001 in our case.

到目前为止,我们没有将应用程序移至端口80。在一台特定的ec2机器上,所有应用程序(一个或多个)都将在其端口上运行,即本例中的3000和3001。

We‘ll just install Nginx in front of the node servers, and run NGINX on port 80 so that it can intercept all internet traffic and route it to the specific port where the required application server ( node server ) will be listening only if the HTTP headers match.

我们将Nginx安装在节点服务器的前面,并在端口80上运行NGINX,以便它可以拦截所有Internet流量并将其路由到所需的应用服务器(节点服务器)仅在HTTP侦听的特定端口。标头匹配。

To make this functionality working follow the below steps:

要使此功能正常工作,请执行以下步骤:

  1. After installing Nginx in previous steps.

    在之前的步骤中安装Nginx之后。
  2. In your ssh terminal, navigate to the /etc/nginx/sites-enabled directory by writing the below command in the terminal.

    在ssh终端中,通过在终端中编写以下命令,导航至/etc/nginx/sites-enabled目录。

$ cd /etc/nginx/sites-enabled

3. Write the below command to unlink the default NGINX template

3.编写以下命令以取消链接默认的NGINX模板

$ sudo unlink default

4. Now, navigate to conf.d folder by writing the below command.

4.现在,通过编写以下命令导航到conf.d 文件夹

$ cd /etc/nginx/conf.d

5. Now create a new file in this directory named as new_sites.conf and start editing using the below command.

5.现在,在此目录中创建一个名为new_sites.conf的新文件,并使用以下命令开始编辑。

$ sudo nano new_sites.conf

Now, write the Nginx config for your server hosted on port 3000 in the editor.

现在,在编辑器中为托管在端口3000上的服务器编写Nginx配置。

server {
listen 80 default_server;
server_name localhost;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

Now, PressCtrl + X and pressY for Save modified buffer and then you will be prompted for entering the name of the file. Just hit enter for saving the file with the same name.

现在,按Ctrl + X并按Y来保存修改后的缓冲区,然后将提示您输入文件名。 只需按Enter即可保存具有相同名称的文件。

Now, run the below command standing in the same directory in which we have created new_sites.conf. The below command will test whether you have written correct NGINX config or not.

现在,在创建new_sites.conf的同一目录中运行以下命令。 以下命令将测试您是否编写了正确的NGINX配置。

$ sudo nginx -t

After running the above command you will get an output like this which means the NGINX config you wrote is correct and you can proceed.

运行上面的命令后,您将获得类似这样的输出,这意味着您编写的NGINX配置是正确的,您可以继续。

Image for post

Now, run the below command in the same directory. The below command will reload NGINX.

现在,在同一目录中运行以下命令。 下面的命令将重新加载NGINX

$ sudo systemctl reload nginx

Now after this go to your browser where we earlier opened the NGINX welcome page. Type the same DNS address or IP again and You’ll see magic.

现在,转到您的浏览器,在此之前我们打开了NGINX欢迎页面。 再次输入相同的DNS地址或IP,您将看到魔术。

Image for post

Hurray!! we just hosted our app on a simple IP address without any port.

欢呼!! 我们只是将应用程序托管在一个没有任何端口的简单IP地址上。

将Nginx配置为每当实例重启时自动启动 (Configure Nginx to autostart whenever instance will be rebooted)

We also need NGINX to get restarted whenever our EC2 instance gets rebooted. Run the following command in your SSH terminal :

每当EC2实例重新启动时,我们还需要NGINX重新启动。 在SSH终端中运行以下命令:

sudo chkconfig nginx on

Now, whenever you reboot your instance the NGINX will also restart.

现在,无论何时重新启动实例,NGINX也会重新启动。

Hurray!! we just set up auto-restart of Nginx on Instance rebooting.

欢呼!! 我们只是在实例重启时设置了Nginx的自动重启。

从Godaddy,Namecheap等购买域名。 (Purchase domains from Godaddy, Namecheap, etc.)

So, you’ve hosted your apps now on a live server. Now, don’t you think it’s very difficult to remember our server IP address for everyone?

因此,您现在已将应用程序托管在实时服务器上。 现在,您难道不认为每个人都很难记住我们的服务器IP地址吗?

54.158.217.172 ( my server ip address )

So, to overcome this problem we will buy a domain name for our website. So Let’s start by understanding the basics.

因此,为克​​服此问题,我们将为我们的网站购买一个域名。 因此,让我们从了解基础知识开始。

What is a Domain Name?

什么是域名?

In General, It is the address of your website that people will use and visit your website by typing in their browsers. If we take an example, then suppose the website is your friend’s house and the domain name is your friend’s house address.

通常,它是人们将通过输入其浏览器来使用并访问您的网站的网站地址。 如果我们举一个例子,那么假设网站是您朋友的房子,域名是您朋友的房子地址。

Technically, The Internet globally is a giant network of computers which are connected to each other. Every computer has an IP address ( series of numbers ) and can communicate with each other through a network. But it looks quite difficult to remember these IP’s of your favourite sites like Amazon, Google, Microsoft, Github, etc.

从技术上讲,Internet在全球范围内是相互连接的庞大计算机网络。 每台计算机都有一个IP地址(一系列数字),并且可以通过网络相互通信。 但是,记住您最喜欢的网站(如亚马逊,谷歌,微软,Github等)的这些IP似乎非常困难。

So, Domain names come in to scene which were invented to solve this problem.

因此,域名问世是为了解决这个问题而发明的。

So, now if you want to visit your favourite websites like Amazon, Github, Google, Microsoft, etc. You don’t have to enter a long string of numbers. You can simply type github.com, amazon.com, google.com, microsoft.com.

因此,现在,如果您想访问自己喜欢的网站,如Amazon,Github,Google,Microsoft等,则无需输入一长串数字。 您只需键入github.com,amazon.com,google.com,microsoft.com。

Now you have got enough information about this all Let’s buy two domain names for our two web apps hosted on the same EC2 machine.

现在您已经获得了足够的信息。让我们为托管在同一EC2计算机上的两个Web应用程序购买两个域名。

Note: I am buying my domains from GoDaddy and Get.tech you can buy your domain from any domain name provider like Namecheap, etc.

注意:我正在从 GoDaddy Get.tech 购买我的域名, 您可以从任何域名提供商(例如Namecheap等)购买您的域名。

Buying domain from GoDaddy

GoDaddy 购买域名

  1. Visit GoDaddy and search for the domain name that you want to buy. The site will provide you with all the details whether the provided domain is available or not.

    访问GoDaddy并搜索您要购买的域名。 该站点将为您提供所有详细信息,无论提供的域是否可用。

  2. You can see I searched for a domain name which is themidnightdev.com which is showing as available.

    您可以看到我搜索了一个域名themidnightdev.com,该域名显示为可用。
Image for post

3. Now, click on Add to cart button in the centre and then click Continue to cart on the top right in green.

3.现在,单击中间的添加到购物车按钮,然后单击绿色右上角的继续购物

Image for post

4. Now, you can select extra products if you want with your domain like Privacy protection for the domain, etc. and also select the no. of years for which you want to buy your domain.

4.现在,如果您想要与您的域一起使用,可以选择其他产品,例如该域的隐私保护等,然后选择“否”。 您要购买域名的年份。

5. Simply click on Checkout and then sign in to your account if you already have your account else create an account it will not take much time. You can also log in through social media.

5.只需单击Checkout ,然后登录到您的帐户(如果您已经拥有您的帐户),否则创建一个帐户将不会花费很多时间。 您也可以通过社交媒体登录。

Image for post

6. I logged in through socially and then you be redirected to the billing information page and then Payment page.

6.我通过社交方式登录,然后将您重定向到“帐单信息”页面和“付款”页面。

Image for post

7. Simply fill out the payment details and you are done.

7.只需填写付款明细即可完成。

Note: This domain name is chosen only for demo and blogging purposes. I am not the owner of this domain nor I am choosing this for advertisement purposes. I will demo further with some another domain name that I’d already bought.

注意:选择此域名仅用于演示和博客目的。 我不是该域的所有者,也不是出于广告目的选择它。 我将使用已经购买的另一个域名进一步演示。

Using the same steps I both my second domain from Get.tech.

使用相同的步骤,我都是来自Get.tech的第二个域。

Hurray!! you just bought a domain name for your web app.

欢呼!! 您刚刚为您的网络应用购买了域名。

为我们的服务器配置域名 (Configure domain name for our server)

I am hoping you’ve bought a cool domain. So Let’s start configuring it with our server. As I described before I am hosting two node apps on a single machine. So, I bought 2 domains as listed below :

我希望您买了一个很酷的域名。 因此,让我们开始使用我们的服务器对其进行配置。 如前所述,我在一台计算机上托管两个节点应用程序。 因此,我购买了以下列出的2个域:

1. fluencyhub.co.in from Godaddy.2. themidnight.tech from Get.tech.

1.来自Godaddy的fluencyhub.co.in.2。 Get.tech的themidnight.tech。

Now, Let’s start configuring it with our server.

现在,让我们开始使用我们的服务器对其进行配置。

  1. Go to your AWS EC2 console and select the EC2 instance on which your node apps are hosted. Copy the IPv4 Public IP address of the instance.

    转到您的AWS EC2控制台并选择托管您的节点应用程序的EC2实例。 复制实例的IPv4公用IP地址。
Image for post

2. Go to Godaddy and login you can see all your domains are listed below.

2.转到Godaddy,然后登录,您会看到下面列出了所有域。

Image for post

3. Click on DNS. Now, you’ll see a panel like this.

3.单击DNS 。 现在,您将看到一个类似的面板。

Image for post

4. Now, click on Add and simply add two records.

4.现在,单击添加,然后简单地添加两个记录

First Record details:

第一记录详细信息:

Type A, Name @, Value server IP address, TTL 600 seconds.

键入A,名称@,值服务器IP地址,TTL 600秒。

Image for post

Second Record details:

第二记录详细信息:

Type A, Name www, Value server IP address, TTL 600 secondsorType CNAME, Name www, Value @, TTL 600 seconds

类型A,名称www,价值服务器IP地址,TTL 600秒或类型CNAME,名称www,值@,TTL 600秒

Image for post

Wait for a few minutes. Now, go and type your domain name in your browser. For example, my domain is www.fluencyhub.co.in .

等待几分钟。 现在,在浏览器中键入您的域名。 例如,我的域名是www.fluencyhub.co.in

Image for post

Hurray!! It is working. we just connected our domain name to one of our web apps.

欢呼!! 这是工作。 我们只是将域名连接到其中一个Web应用程序。

Simply add the same DNS details in your other domain DNS settings also which is themidnight.tech in my case.

只需在您的其他域DNS设置中添加相同的DNS详细信息,就我而言,这也是themidnight.tech。

Note: To host multiple node apps on the same EC2 instance and accessible using different domains we need to change the NGINX config.

注意:要在同一EC2实例上托管多个节点应用程序并使用不同的域进行访问,我们需要更改NGINX配置。

Let’s change the NGINX config for our multiple node apps shown below:

让我们为以下所示的多节点应用程序更改NGINX配置:

Image for post

The first app on port 3000 already integrated with our domain name

端口3000上的第一个应用程序已经与我们的域名集成

Image for post

Second app on port 3001

端口3001上的第二个应用

Image for post
  1. Open your terminal and SSH into the EC2 instance.

    打开您的终端,并通过SSH进入EC2实例。
  2. Now, navigate to /etc/nginx/conf.d directory by writing the below command.

    现在,通过编写以下命令导航到/etc/nginx/conf.d目录。

$ cd /etc/nginx/conf.d

3. Now open the previously created file in this directory named as new_sites.conf and start editing using the below command.

3.现在,在此目录中打开先前创建的文件,名称为new_sites.conf,并使用以下命令开始编辑。

$ sudo nano new_sites.conf

4. Now, write the Nginx config for your node server hosted on port 3000 and port 3001 in the editor. Remove all the content we have written before and copy and paste the below content in that file.

4.现在,在编辑器中为托管在端口3000和端口3001上的节点服务器编写Nginx配置。 删除我们之前编写的所有内容,然后将以下内容复制并粘贴到该文件中。

server {
listen 80 default_server;
server_name fluencyhub.co.in www.fluencyhub.co.in;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:3000;
}
}server {
listen 80;
server_name themidnight.tech www.themidnight.tech;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:3001;
}
}

Now, PressCtrl + X and pressY for Save modified buffer and then you will be prompted for entering the name of the file. Just hit enter for saving the file with the same name.

现在,按Ctrl + X并按Y来保存修改后的缓冲区,然后将提示您输入文件名。 只需按Enter即可保存具有相同名称的文件。

Now, run the below command standing in the same directory in which we have created new_sites.conf. The below command will test whether you have written correct Nginx config or not.

现在,在创建new_sites.conf的同一目录中运行以下命令。 以下命令将测试您是否编写了正确的Nginx配置。

$ sudo nginx -t

After running the above command you will get an output like this which means the NGINX config you wrote is correct and you can proceed.

运行上面的命令后,您将获得类似这样的输出,这意味着您编写的NGINX配置是正确的,您可以继续。

Image for post

Now, run the below command in the same directory. The below command will reload NGINX.

现在,在同一目录中运行以下命令。 下面的命令将重新加载NGINX。

$ sudo systemctl reload nginx

Now after this go to your browser and open your all the domains in different tabs.

现在,在此之后转到浏览器并在不同选项卡中打开所有域。

Image for post
Image for post

Hurray!! we connected both our domains to our web apps.

欢呼!! 我们将两个域都连接到了Web应用程序。

为我们的服务器配置子域 (Configure subdomains for our server)

Now, our simple domain connection to our web apps is done. Then what about subdomains.

现在,完成了到Web应用程序的简单域连接。 那子域呢?

Generally, Subdomains are a great way to separate areas of your site. As the name suggests sub-domains means a subpart of the domain.

通常, 子域是分隔站点区域的好方法。 顾名思义,子域是域的子部分。

Let’s follow the below steps to add a subdomain named as dev.fluencyhub.co.in

让我们按照以下步骤添加一个名为dev.fluencyhub.co.in的子域

  1. Go to GoDaddy, log in and navigate to the DNS settings panel which we visited in the above step.

    转到GoDaddy,登录并导航到我们在上一步中访问的DNS设置面板。
  2. Click on Add DNS and simply add a Record like below one.

    单击“ 添加DNS”,然后简单地添加一条如下所示的记录

  3. Type A, Name dev, Value server IP address, TTL 600 seconds.

    类型A,名称开发,价值服务器IP地址,TTL 600秒。
Image for post

3. Now we also need to edit the NGINX config. So, Open your terminal and SSH into the EC2 instance and navigate to conf.d folder .Now, start editing the new_sites.conf file.

3.现在我们还需要编辑NGINX配置。 因此,打开您的终端并通过SSH进入EC2实例,并导航到conf.d folder 。现在,开始编辑new_sites.conf文件。

$ sudo nano new_sites.conf

4. Now, update the Nginx config for your subdomain on node server hosted on port 3000 which is fluencyhub.co.in. Update the line highlighted in the bolded form below and PressCtrl + X and pressY for Save modified buffer and then you will be prompted for entering the name of the file. Just hit enter for saving the file with the same name.

4.现在,在fluencyhub.co.in端口3000上托管的节点服务器上,为您的子域更新Nginx配置。 更新下面以粗体显示的行,然后按Ctrl + X并按Y表示保存已修改的缓冲区,然后将提示您输入文件名。 只需按Enter即可保存具有相同名称的文件。

server {
listen 80 default_server;
server_name fluencyhub.co.in www.fluencyhub.co.in dev.fluencyhub.co.in;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:3000;
}
}server {
listen 80;
server_name themidnight.tech www.themidnight.tech;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://127.0.0.1:3001;
}
}

Now, run the below command standing in the same directory in which we have created new_sites.conf. The below command will test whether you have written correct Nginx config or not.

现在,在创建new_sites.conf的同一目录中运行以下命令。 以下命令将测试您是否编写了正确的Nginx配置。

$ sudo nginx -t

After running the above command you will get an output like this which means the NGINX config you wrote is correct and you can proceed.

运行上面的命令后,您将获得类似这样的输出,这意味着您编写的NGINX配置是正确的,您可以继续。

Image for post

Now, run the below command in the same directory. The below command will reload NGINX.

现在,在同一目录中运行以下命令。 下面的命令将重新加载NGINX。

$ sudo systemctl reload nginx

Now after this go to your browser and open your subdomain which is dev.fluencyhub.co.in in our case in a new tab.

现在,在此之后转到浏览器并在新选项卡中打开您的子域(在本例中为dev.fluencyhub.co.in)。

Note: If you get confused in this step then follow this step same as the above step which is explained more thoroughly.

注意:如果您在此步骤中感到困惑,请按照与上述步骤相同的步骤进行操作,此步骤将得到更全面的说明。

Image for post

Hurray!! You have connected a subdomain to our node app.

欢呼!! 您已将子域连接到我们的节点应用程序。

Now, everything is done we hosted our web app successfully and connected it to domains. Wait Really? Don’t you think our URL in the browser looks something weird?

现在,一切都已完成,我们成功托管了Web应用程序并将其连接到域。 真的等吗 您不觉得我们浏览器中的URL看起来很奇怪吗?

Image for post

Yes, it is displaying Not Secure. But why?It is because we do not have SSL certificates for our domain. So, our website is following the HTTP protocol. Let’ continue to next step and I’ll explain how to move our domain from HTTP to HTTPS.

是的,它显示不安全 。 但是为什么呢?这是因为我们的域没有SSL证书。 因此,我们的网站遵循HTTP协议。 让我们继续下一步,我将解释如何将域从HTTP移到HTTPS。

使用Cloudflare设置SSL (Setup SSL with Cloudflare)

Now, to move our app from HTTP to HTTPS we need SSL certification for our domains. For this, I am using a service called Cloudflare.

现在,要将我们的应用程序从HTTP迁移到HTTPS,我们需要对域进行SSL认证。 为此,我正在使用一项名为Cloudflare的服务。

Image for post

Let’s create an account on Cloudflare first.1. Go to Cloudflare. Click on Signup.

我们首先在Cloudflare上创建一个帐户。 转到Cloudflare 。 点击注册

Image for post

2. Fill your details and click on Create Account.

2.填写您的详细信息,然后单击创建帐户

Image for post

3. Now add your domain name on the next page after signup on the add site page, In case the Add site page is not displayed then just click on the Add Site button on the top. After adding your domain without any protocol and www. Click on Add site. For example: fluencyhub.co.in

3.现在,在添加站点页面上注册后,在下一页添加您的域名,如果未显示“添加站点”页面,则只需单击顶部的“ 添加站点”按钮。 添加没有任何协议和www的域之后。 单击添加站点 。 例如:fluencyhub.co.in

Image for post

4. Now, this page will appear. Just choose the free plan and click on Confirm plan.

4.现在,将显示此页面。 只需选择免费计划,然后单击确认计划

Image for post

5. Now, It will fetch the DNS information of your domain. Verify it and just click on Continue.

5.现在,它将获取您域的DNS信息。 进行验证,然后单击“ 继续”

Image for post

6. Now, it will ask you to add the new nameservers show on the screen and remove the old nameservers in your Godaddy account or any other site from where you bought your domain.

6.现在,它将要求您添加屏幕上显示的新名称服务器,并删除您的Godaddy帐户或购买域名的任何其他网站中的旧名称服务器。

Image for post

7. Copy both name servers. In my case the nameservers are :

7.复制两个名称服务器。 就我而言,名称服务器是:

hera.ns.cloudflare.com
tosana.ns.cloudflare.com

8. Go to Godaddy and log in to your account. Go to DNS settings of your selected domain.

8.转到Godaddy并登录到您的帐户。 转到所选域的DNS设置。

Image for post

9. Scroll down on your DNS settings page and click on Change in Nameservers Card. Shown below.

9.向下滚动您的DNS设置页面,然后单击“ 更改名称服务器卡”。 如下所示。

Image for post

10. Now, this page will appear. Click on Enter my own nameservers (advanced) button.

10.现在,将显示此页面。 单击输入我自己的名称服务器(高级)按钮。

Image for post

11. Now, by filling the nameservers. Just click on the Save button.

11.现在,通过填充名称服务器。 只需单击“ 保存”按钮。

Image for post

12. Now, you will see your nameservers updated on the next screen. If old nameservers also appear just refresh your page once.

12.现在,您将在下一个屏幕上看到名称服务器已更新。 如果旧的域名服务器也出现,只需刷新您的页面一次。

Image for post

13. Now, go back to Cloudflare and click on Done, check nameservers.

13.现在,返回Cloudflare并单击完成,检查名称服务器

Image for post

14. Now, Cloudflare will ask a few more information about the domain.

14.现在,Cloudflare将询问有关该域的更多信息。

Image for post

15. For Improve security Panel, Select SSL/TLS encryption mode to Flexible and click on Save. Don’t worry you can change it later on in your settings if you want and also if these panels do not appear you can change it in your settings by selecting a domain in Cloudflare.

15.对于“改进安全性面板”,将SSL / TLS加密模式选择为“灵活”,然后单击“ 保存” 。 不用担心,以后可以根据需要在设置中进行更改,如果这些面板没有出现,也可以通过在Cloudflare中选择域来更改设置。

Image for post

16. Now, It will ask for Always use HTTPS. Turn ON this by default it will be OFF. So, after turning it on Click on Save.

16.现在,它将要求始终使用HTTPS。 默认情况下将其打开,它将关闭。 因此,将其打开后,单击“ 保存”

Image for post

17. You can simply choose default values for next steps by simply clicking on Save.

17.您只需单击保存 ,即可为后续步骤选择默认值。

Image for post
Image for post

18. After this simply click on Finish.

18.之后,只需单击Finish

Image for post

19. Now, you will be redirected to a check nameservers page. Similar to the one you saw previously. Now, Simply click on Re-check now.

19.现在,您将被重定向到检查名称服务器页面。 与您之前看到的类似。 现在,只需单击立即重新检查

Image for post

20. After rechecking this message will appear.

20.重新检查后,将出现此消息。

Image for post

After performing these all steps. You are done. Simply wait for a few minutes and go and check your web app by entering your domain in the browser in a new tab.

完成所有步骤后。 大功告成 只需等待几分钟,然后在浏览器中的新标签页中输入您的域,即可检查您的Web应用程序。

Image for post

You can see a lock icon is appearing which means it has an SSL certificate and is an HTTPS domain.

您可以看到出现了一个锁定图标,这意味着它具有SSL证书并且是HTTPS域。

Image for post

Simply connect your other apps similarly with your Cloudflare account.

只需将您的其他应用程序类似地与您的Cloudflare帐户关联即可。

Now, if you go to your Cloudflare account. It will display a green tick on your domain means the SSL is working on this domain.

现在,如果您转到Cloudflare帐户。 它会在您的域上显示一个绿色的勾号,表示SSL正在该域上运行。

Image for post

Hurray!! you just moved your domain from HTTP to HTTPS.

欢呼!! 您刚刚将域从HTTP移到了HTTPS。

Congratulations!! You have hosted your multiple apps, connected to domain and subdomains, moving your domain from HTTP to HTTPS.

恭喜!! 您已经托管了多个应用程序,它们已连接到域和子域,并将域从HTTP移到HTTPS。

Please feel free to reach me in case of queries.

如有查询,请随时与我联系。

翻译自: https://medium.com/@nitin.malhotra/deploy-single-multiple-node-js-750ee6fee782

nginx子域名配置

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值