To install Nginx on an Amazon EC2 instance running a Linux-based operating system, you can follow these general steps. Note that the specific commands may vary slightly depending on the Linux distribution you are using.
1. Connect to your EC2 instance:
Use SSH to connect to your EC2 instance. Replace your-instance-ip
with your actual instance’s public IP address, and your-key.pem
with the path to your private key file:
ssh -i "your-key.pem" ec2-user@your-instance-ip
2. Update the package repository:
Update the package repository to ensure you have the latest information about available packages:
sudo yum update
3. Install Nginx:
For Amazon Linux or Amazon Linux 2, you can install Nginx using the following command:
sudo amazon-linux-extras install nginx1
If you are using a different Linux distribution, you may use the distribution’s package manager. For example, on Ubuntu/Debian, you can use:
sudo apt-get update
sudo apt-get install nginx
4. Start Nginx:
sudo service nginx start
5. Enable Nginx to start on boot:
Ensure Nginx starts automatically when the server boots:
sudo chkconfig nginx on # For Amazon Linux or Amazon Linux 2
or
sudo systemctl enable nginx # For other distributions using systemd
6. Test Nginx:
Open a web browser and enter your EC2 instance’s public IP address in the address bar. You should see the default Nginx welcome page.
That’s it! You’ve successfully installed Nginx on your Amazon EC2 instance. Remember to configure Nginx according to your specific requirements, such as setting up server blocks (virtual hosts) or securing your server with SSL certificates if needed.