如何在AWS EC2 Linux 2上安装NGINX [英] How to install NGINX on AWS EC2 Linux 2

查看:1474
本文介绍了如何在AWS EC2 Linux 2上安装NGINX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是AWS的新用户,试图了解我应该在实例上安装哪个版本的NGINX.我发现了多种选择;

I'm new to AWS and trying to understand which version of NGINX I should be installing on my instance. I've found multiple options;

  • Via EPEL as the blog entry
  • Amazon's own (?) version as this answer
  • The 2016 NGINX official tutorial

在开发环境(Centos VM)上,我使用了sudo yum install nginx.尝试过EPEL路线后,我没有进行相同的设置,特别是未将启用/可用的站点作为创建的一部分进行创建.我想使用 nginxconfig.io ,它需要这些.我应该使用哪个版本的NGINX?

On my development environment (Centos VM) I used sudo yum install nginx. Having tried the EPEL route I don't get the same set up, in particular sites enabled/available is not created as part of the setup. I want to use nginxconfig.io which requires those. Which version of NGINX should i use for that?

推荐答案

我个人将使用亚马逊自己的存储库.

I'd personally use Amazon's own repo.

Amazon存储库提供的版本相对较旧(在撰写本文时为1.12.2).要查看亚马逊存储库可以运行哪些版本

The version provided by the Amazon repo is relatively old (1.12.2 at the time of writing). To see what versions the Amazon repo has access to run

amazon-linux-extras list | grep nginx

如果您想要更高的版本,请考虑使用EPEL.

If you'd like a later version, consider EPEL.

关于配置,最好的选择是将所需的配置显式提供给服务器.

In regards to the config, your best bet is to explicitly supply the configuration you require to the server.

使用现成的工具可以使您正常运行.但是,当Nginx更新时,您会面临发生变化的风险.明确提供您自己的配置可让您更好地控制正在运行的内容.

Using the off-the-peg ones are fine to get you up and running. However you run the risk of things changing when Nginx updates. Explicitly supplying your own configuration gives you greater control over what is running.

可能最简单的方法是将nginxconfig.io生成的配置上载到S3.

Probably the simplest approach would be to upload the configuration generated by nginxconfig.io to S3.

然后在创建EC2实例以下载配置时通过用户数据添加脚本.

Then add a script via user data when creating the EC2 instance to download your configuration.

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html

类似这样的事情...

Something like this...

#!/bin/bash

# Install Nginx
amazon-linux-extras install nginx1.12

# Back up existing config
mv /etc/nginx /etc/nginx-backup

# Download the configuration from S3
aws s3 cp s3://{my_bucket}/nginxconfig.io-example.com.zip /tmp

# Install new configuration
unzip /tmp/nginxconfig.io-example.com.zip -d /etc/nginx

nginxconfig.io提供的配置设置为您启用/可用的所有站点.

The configuration supplied by nginxconfig.io sets up all the sites enabled/available for you.

这篇关于如何在AWS EC2 Linux 2上安装NGINX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆