How to install NGINX on AWS EC2 Linux 2

一世执手 提交于 2020-08-26 20:00:29

问题


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

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?


回答1:


I'd personally use Amazon's own repo.

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

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.

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.

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

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

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




回答2:


Alternative way to install that could be easier (has a fairly recent version of Nginx):

$ sudo amazon-linux-extras list | grep nginx
 38  nginx1=latest            disabled      [ =stable ]

$ sudo amazon-linux-extras enable nginx1
 38  nginx1=latest            enabled      [ =stable ]

Now you can install:
# yum clean metadata
# yum install nginx

$ sudo yum -y install nginx

$ nginx -v
nginx version: nginx/1.16.1


来源:https://stackoverflow.com/questions/57784287/how-to-install-nginx-on-aws-ec2-linux-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!