← Back to list

Deploying a Gradio App on AWS EC2 with Nginx Reverse Proxy

A production-friendly guide to hosting AI applications securely with Gradio, AWS, and Nginx

Shaktikantadas · 2026-05-28 19:44 · 4 claps · 2.8 min read
#technology #ai #gradio #software-development #aws
Open on Medium ↗
Wiki topics: AI · AI · General ☁️ · DevOps & Cloud 🎵 · Music & Audio

Deploying a Gradio App on AWS EC2 with Nginx Reverse Proxy

A production-friendly guide to hosting AI applications securely with Gradio, AWS, and Nginx

Building AI applications with Gradio is incredibly fast. But deploying them properly inside enterprise environments is a different challenge altogether.

Most organizations do not allow applications to expose random ports directly to the internet. Instead, applications are usually deployed behind controlled HTTP routes and reverse proxies like Nginx.

In this article, we will deploy a Gradio application on an AWS EC2 instance using Nginx as a reverse proxy.

This setup is:

  • Simple
  • Production-friendly
  • Secure
  • Enterprise demo compatible

It also works well for:

  • Internal AI tools
  • RAG applications
  • Agentic AI systems
  • Enterprise demos
  • Multi-user GenAI applications

Architecture Overview

```Browser → Nginx (Port 80) → Gradio App (Port 7860)```

Here:

Gradio runs internally on the server

Nginx forwards incoming requests

Users access the app through HTTP routes

Step 1: Launch an EC2 Instance

Create an Ubuntu EC2 instance.

Recommended configuration:

  • Ubuntu 22.04
  • t2.micro or higher

During setup:

  • Download the PEM key
  • Allow SSH access

Step 2: Configure Security Groups

Go to:

  • EC2 → Security Groups → Inbound Rules

Allow:

  • Port 22 → SSH
  • Port 80 → HTTP

You can whitelist trusted IPs instead of allowing global access.

Example:

  • My IP → Port 80

This helps restrict access to trusted networks only.

Step 3: SSH Into the Server

ssh -i your-key.pem ubuntu@your-server 

Update packages:

sudo apt update && sudo apt upgrade -y 

Step 4: Install Python and Gradio

Install pip:

sudo apt install python3-pip -y 

Install Gradio:

pip install gradio 

Optional virtual environment:

python3 -m venv venv source venv/bin/activate 

Step 5: Create the Gradio Application

Create a file called app.py

import gradio as gr def greet(name): return f"Hello {name}" demo = gr.Interface( fn=greet, inputs="text", outputs="text" ) demo.launch( server_name="0.0.0.0", server_port=7860 ) 

Important:

server_name="0.0.0.0"

This allows Nginx to communicate with the Gradio service properly.

Step 6: Install Nginx

sudo apt install nginx -y 

Start Nginx:

sudo systemctl start nginx sudo systemctl enable nginx 

Step 7: Configure Nginx Reverse Proxy

Create a configuration file:

sudo nano /etc/nginx/sites-available/gradio 

Paste:

server { listen 80; server_name _; location / { proxy_pass http://127.0.0.1:7860; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_buffering off; } } 

Important:

proxy_buffering off;

Without this, Gradio CSS and frontend assets may not load properly in some cases.

The websocket headers are also important for proper frontend communication.

Optional: Host the App Under a Custom Route

Instead of exposing the app directly at /, you can host it under a custom route like:

http://your-server/demoapp

This is useful when:

Hosting multiple applications

Organizing internal tools

Following enterprise URL structures

Update Nginx configuration:

server { listen 80; server_name _; location /demoapp/ { proxy_pass http://127.0.0.1:7860/; proxy_http_version 1.1; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_buffering off; } } 

Now update the Gradio app:

demo.launch( server_name="0.0.0.0", server_port=7860, root_path="/demoapp" ) 

Important:

root_path="/demoapp" 

Without this, Gradio may fail to load:

  • CSS
  • frontend assets
  • websocket routes

because it still assumes the application is hosted at the root path.

Step 8: Enable the Configuration

sudo ln -s /etc/nginx/sites-available/gradio /etc/nginx/sites-enabled/ 

Test configuration:

sudo nginx -t 

Restart Nginx:

sudo systemctl restart nginx 

Step 9: Run the Gradio App

Start the application:

python3 app.py 

Once the service is running, open the configured route in the browser.

Your Gradio application should now be accessible through Nginx.

Keeping the Application Running

If the SSH session closes, the application stops.

Quick solution:

nohup python3 app.py & 

Better options:

  • tmux
  • screen
  • systemd

For production deployments, systemd is recommended.

Common Issues

Gradio UI opens but CSS is broken

Usually fixed by:

  • proxy_buffering off
  • Proper websocket headers
  • Correct root_path
  • Restarting Nginx

App not accessible

Check:

  • Security group rules
  • Nginx status
  • Application port
  • Reverse proxy configuration
  • Nginx configuration issues

Run:

sudo nginx -t 

Then restart:

sudo systemctl restart nginx 

Final Thoughts

Deploying Gradio behind Nginx on EC2 is one of the simplest ways to move from local AI experimentation to real-world accessible applications.

This setup provides:

  • Cleaner architecture
  • Better access control
  • Stable deployment flow
  • Production-friendly routing

Once comfortable with this setup, you can further expand into:

  • HTTPS with SSL
  • Docker containers
  • CI/CD pipelines
  • GPU-backed inference
  • Kubernetes deployments
  • Enterprise AI platforms

The ability to deploy AI interfaces reliably is becoming an essential skill for modern AI engineers.


메타데이터
post_id
faae47279baa
slug
deploying-a-gradio-app-on-aws-ec2-with-nginx-reverse-proxy-faae47279baa
url
https://medium.com/@shaktikantadas14/deploying-a-gradio-app-on-aws-ec2-with-nginx-reverse-proxy-faae47279baa
canonical_url
https://medium.com/@shaktikantadas14/deploying-a-gradio-app-on-aws-ec2-with-nginx-reverse-proxy-faae47279baa
author_url
https://medium.com/@shaktikantadas14
status
ok
fetched_at
2026-06-09 15:37:30