Background


ChatGPT Next Web is a widely used ChatGPT web UI project that enables you to deploy a website to your own server using only your Open API key. This allows you to enjoy the same chat experience without having to visit the official Open AI website, which is particularly useful when dealing with network or regional restrictions.

However, the official repository of ChatGPT Next Web does not offer a one-click installation for Azure, and the developer has no plans to add a built-in login feature to restrict access to the website. To address these issues, my goal is to:

  1. Deploy ChatGPT Next Web to Azure without the need to create a VM.
  2. Add access control that requires individual accounts to log in to use ChatGPT, without making any changes to the code.

My objective is to complete these tasks within three minutes. Let's explore how this can be achieved.

Create Azure App Service


The official ChatGPT Next Web provides a Docker image. This is how I can run it on Azure without VM. Azure has many PaaS ways to deploy Docker containers:

  1. Azure App Service
  2. Azure Container Instance
  3. Azure Container Apps
  4. AKS

I choose App Service because it has built in Authentication features that I will use in the next step.

Go to Azure Portal, create a new Web App, select Docker Container + Linux in instance details.

For pricing plans, as I tested, Basic SKUs are enough for a few users, you can choose a higher SKU if you have a lot more end users.

In Docker step, use single container from public Docker Hub, named: yidadaa/chatgpt-next-web

Configure other steps as you like, and finish creating the web app.

Configure Environment Variables


After creating the Web App, we need to configure two environment variables for the Docker container before running the application.

Go to Configuration blade, and add two settings:

  1. OPENAI_API_KEY: Use your own key bought from Open API official website, usually start with "sk-"
  2. PORT: 443

I would also suggest turn on HTTP2 in general settings for better performance.

By now, your ChatGPT web UI is ready to run. You can access the page by default domain or bind your custom domain.

Enable Authentication


By default, your website is publicly accessible from anywhere on the Internet. This can blow up your credit card. We need to enable authentication that asks users to login before using the application.

Although the original ChatGPT Next Web project did not have such features, it is extremely easy to add login providers on Azure without writing any code.

Go to Authentication blade, click "Add identity provider"

You can add any of the listed providers. I am using Microsoft for example. 

For Microsoft provider, by default, all accounts in the given Azure AD will have access. To limit accounts to only selected people, see my previous blog post How to Allow Only Selected Users to Access an Application in Azure AD

After completing this step. Users will be asked to login before opening ChatGPT web UI. 

Conclusion


Azure App Service is a wonderful PaaS service. It can run Docker based applications and add individual account login flow to the application without modifying code. All steps are just a few mouse clicks that can be finished in a few minutes.