Deployment guide

Nginx

Overview

NGINX is a high-performance web server, reverse proxy and load balancer. It is known for its stability, low resource consumption and ability to handle a large number of concurrent connections.

This guide shows you how to deploy and configure NGINX on Linux from the SecureAnyCloud AMI on the AWS Marketplace.

What you get:

  • The NGINX web server with the default configuration on port 80
  • A preconfigured systemd service that starts NGINX automatically on boot
  • The default web root at /usr/share/nginx
  • An OS package update script that keeps the system current
  • AWS CLI v2 for AWS service integration
  • Systems Manager Agent (SSM) for remote management
  • CloudWatch Agent for monitoring
  • The latest security patches, applied at build time
  • 24/7 SecureAnyCloud support with a guaranteed 24-hour response SLA

Prerequisites

Before you launch this AMI, you need:

  • An active AWS account
  • An active subscription to the NGINX listing on AWS Marketplace
  • An EC2 key pair for SSH access
  • Familiarity with EC2 instance management and SSH

Recommended instance type: t3.small (2 vCPU, 2 GB RAM) or larger. The minimum requirements are 1 vCPU, 1 GB RAM and 20 GB of disk space. NGINX is lightweight and performs well even on smaller instances.

1

Launch the AMI

  1. Go to the AWS Marketplace and search for "NGINX SecureAnyCloud".
  2. Choose Continue to Subscribe, accept the terms, then choose Continue to Configuration.
  3. Select your preferred Region and Software Version.
  4. Choose Continue to Launch.
  5. Choose Launch through EC2 for full control over the instance configuration.
  6. Select your instance type (t3.small recommended).
  7. Configure storage with a minimum of 20 GB gp3.
  8. Configure your Security Group with the following inbound rules.

Port Protocol Source Purpose

22 TCP Your IP SSH access

80 TCP 0.0.0.0/0 NGINX web server (HTTP)

443 TCP 0.0.0.0/0 NGINX web server (HTTPS, if configured)

Select your EC2 key pair and launch the instance.

2

Connect over SSH

Once your instance is running and has passed both status checks (2/2), connect over SSH:

ssh -i your-key.pem ec2-user@<public-ip-address>

Replace your-key.pem with the path to your EC2 key pair and <public-ip-address> with your instance's public IP address.

Important: Wait for the instance to reach 2/2 successful status checks before you connect. If you connect too early, you may see errors such as:

Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

These errors are expected during the initial boot. Wait for both status checks to pass, then try again.

To switch to the root user, run:

sudo su -
3

Verify NGINX is running

NGINX starts automatically on boot. Verify that the service is running:

systemctl status nginx

Open your web browser and go to:

http://<public-ip-address>:80

You should see the default NGINX welcome page, which confirms that the server is running and accessible.

4

Deploy your website

The default web root is /usr/share/nginx/html. To deploy your own content, replace the files in this directory.

Upload files with SCP:

scp -i your-key.pem -r ./my-website/* ec2-user@<public-ip-address>:/tmp/

Then move the files to the web root:

sudo cp -r /tmp/my-website/* /usr/share/nginx/html/

Set the correct permissions:

sudo chown -R nginx:nginx /usr/share/nginx/html/
sudo chmod -R 755 /usr/share/nginx/html/

Configure virtual hosts

To serve multiple websites from a single NGINX instance, create server block configuration files.

Create a new server block:

sudo vi /etc/nginx/conf.d/mysite.conf

Example server block configuration:

server { listen 80; server_name mysite.example.com; root /var/www/mysite; index index.html; location / { try_files $uri $uri/ =404; } access_log /var/log/nginx/mysite_access.log; error_log /var/log/nginx/mysite_error.log; }

Test the configuration and reload:

sudo nginx -t sudo systemctl reload nginx

Configure a reverse proxy

NGINX is commonly used as a reverse proxy that forwards requests to application servers.

Example reverse proxy configuration:

sudo vi /etc/nginx/conf.d/proxy.conf
server { listen 80; server_name app.example.com; location / { proxy_pass http://127.0.0.1:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
sudo nginx -t sudo systemctl reload nginx

Server components

Component Install Path

NGINX /etc/nginx

Note: The automatic OS package update script may update component versions on first boot.

Filesystem layout

Mount Point Size Description

/ 38 GB Root filesystem

/boot 2 GB Operating system kernel files

/usr/share/nginx 9.8 GB NGINX web server root

Key NGINX directories:

Directory Purpose

/etc/nginx Main configuration directory

/etc/nginx/nginx.conf Primary configuration file

/etc/nginx/conf.d/ Additional server block configurations

/usr/share/nginx/html Default web root

/var/log/nginx Access and error logs

/var/cache/nginx Cached content

Manage the NGINX service

systemd manages NGINX, and it starts automatically on boot.

Check service status:

systemctl status nginx

Stop NGINX:

systemctl stop nginx

Start NGINX:

systemctl start nginx

Restart NGINX:

systemctl restart nginx

Reload configuration without downtime:

systemctl reload nginx

Test configuration syntax:

nginx -t

Scripts and log files

Script/Log Path Description

initial_boot_update.sh /stage/scripts Updates the OS with the latest packages on first boot

initial_boot_update.log /stage/scripts Output log for the boot update script

NGINX logs:

Log File Path Description

access.log /var/log/nginx/access.log HTTP request log

error.log /var/log/nginx/error.log Error and diagnostic log

On startup

An OS package update script runs on first boot to bring the image fully up to date. To disable it, remove the script and its crontab entry:

rm -f /stage/scripts/initial_boot_update.sh crontab -e
# Delete the following line, save and exit: @reboot /stage/scripts/initial_boot_update.sh

Troubleshooting

You cannot reach NGINX on port 80

  • Verify that NGINX is running: systemctl status nginx
  • Check that your security group allows inbound traffic on port 80
  • Ensure that the instance has passed 2/2 status checks
  • Check the error logs: tail -f /var/log/nginx/error.log

The configuration test fails

  • Run nginx -t to see the exact error and line number
  • Look for common issues: missing semicolons, unclosed brackets and duplicate server_name values
  • Check for syntax errors in the files under /etc/nginx/conf.d/

You get a 403 Forbidden error

  • Check file ownership. Files should be owned by nginx:nginx
  • Check directory permissions. Directories need 755 and files need 644
  • Verify that the root directive in your server block points to the correct path
  • Check SELinux with getenforce. If it is enforcing, adjust the contexts with chcon -R -t httpd_sys_content_t /var/www/mysite

You get a 502 Bad Gateway error (when using NGINX as a reverse proxy)

  • Verify that the backend application is running on the expected port
  • Check that the proxy_pass URL is correct
  • Review the NGINX error logs: tail -f /var/log/nginx/error.log

Security recommendations

  • Enable HTTPS. Install an SSL certificate from Let's Encrypt (certbot) or use your own certificate
  • Hide the server version. Add server_tokens off; to the http block in /etc/nginx/nginx.conf
  • Restrict sensitive paths. Use location blocks with deny all for admin areas
  • Enable rate limiting. Use limit_req_zone to protect against brute-force attacks
  • Configure security headers. Add headers such as X-Content-Type-Options, X-Frame-Options and Content-Security-Policy
  • Keep NGINX updated. Update regularly with yum update nginx
  • Monitor access logs. Review /var/log/nginx/access.log for suspicious requests
  • Use firewall rules. Restrict SSH access to your IP address and open only the ports you need

Support

If you have any issues with this product, contact SecureAnyCloud support:

  • Email: sales@secureanycloud.com
  • Website: secureanycloud.com
  • Support hours: 24/7, with a guaranteed 24-hour response SLA

Deploy on AWS

Launch NGINX with 24/7 support from SecureAnyCloud.

View on Marketplace

Need Help?

Our support team is available 24/7.

sales@secureanycloud.com