How to Make n8n Work on Your Own Website with Google Login and HTTPS: No Code Required


By the end of this guide, you will:

  • Understand why OAuth redirect errors happen in cloud-hosted n8n
  • Set up a public domain and map it to your EC2/VPS instance
  • Use NGINX as a reverse proxy inside Docker
  • Configure Let’s Encrypt SSL using Certbot and Docker volumes
  • Run n8n with environment variables for correct redirect behavior
  • Successfully authenticate Google integrations (like Google Sheets or Gmail)
  • Automate SSL certificate renewal

This post is perfect for:

  • Developers setting up n8n for the first time
  • DevOps engineers automating workflows
  • Startup teams using n8n in production

Anyone tired of fighting with localhost redirects!

Why “localhost” Breaks Google OAuth in n8n

When n8n generates an OAuth request, it includes a callback URL. By default, if not configured, it uses:

http://localhost:5678/rest/oauth2-credential/callback

So, after a user authenticates via Google, it tries to redirect to your laptop, not your server!

Google’s servers obviously can’t access your local machine, so it fails with:

“redirect_uri_mismatch” or “site can’t be reached”

💡 The Fix

Tell n8n to use your real domain (e.g., https://mydomain.com) instead of localhost. I will show how to do that with Docker.

Configure Your Domain and DNS for n8n

Let’s assume you own mydomain.com.

Steps:

  1. Log in to your DNS provider (e.g., Cloudflare, GoDaddy, Namecheap)
  2. Add an A Record:
    • Host: @ or n8n
    • Points to: your EC2 server’s public IP
    • TTL: Automatic or 1 hour

This connects n8n.mydomain.com or mydomain.com to your server.

You can confirm it’s working with:

ping mydomain.com

curl http://mydomain.com

Using Docker to Run NGINX and Certbot for SSL

Instead of installing NGINX and Certbot manually, we’ll Dockerize both.

docker-compose.yml
version: ‘3’

services:
  nginx:
  image: nginx:latest
  container_name: nginx-proxy
   ports:
    – “80:80”
    – “443:443”
   volumes:
    – ./nginx/nginx.conf:/etc/nginx/nginx.conf
    – ./certbot/conf:/etc/letsencrypt
    – ./certbot/www:/var/www/certbot
   restart: always
   networks:
   – nginx-net

   certbot:
    image: certbot/certbot
   container_name: certbot
   volumes:
    – ./certbot/conf:/etc/letsencrypt
    – ./certbot/www:/var/www/certbot
   entrypoint: >
   /bin/sh -c “trap exit TERM; while :; do
   certbot renew –webroot -w /var/www/certbot;
   sleep 12h;
   done”
   networks:
    – nginx-net

 networks:
   nginx-net:
   external: true

Tip: Don’t forget to create the external network if it doesn’t exist:

docker network create nginx-net

Generate SSL Certificates with Certbot in Docker

Step 1: Serve the ACME challenge

docker-compose.yml
Create a default.conf: server {
  listen 80;
   server_name mydomain.com;

   root /var/www/certbot;

   location /.well-known/acme-challenge/ {
   allow all;
}

   location / {
    return 404;
   }
}

Run temporary NGINX container:

docker-compose.yml
docker run -d –name temp-nginx \
    -p 80:80 \
    -v $(pwd)/certbot/www:/var/www/certbot \
    -v $(pwd)/nginx/default.conf:/etc/nginx/conf.d/default.conf \
    nginx:alpine


Step 2: Request SSL certificate

docker-compose.yml
docker run –rm \
    -v $(pwd)/certbot/www:/var/www/certbot \
    -v $(pwd)/certbot/conf:/etc/letsencrypt \

    certbot/certbot certonly \
    –webroot -w /var/www/certbot \
    -d mydomain.com \
    –agree-tos –no-eff-email \
    -m you@example.com

Stop the temp server:

  docker rm -f temp-nginx

Run n8n with Correct Domain and HTTPS Settings

Finally, run your n8n container with correct environment variables:

docker-compose.yml
sudo docker run -it –rm \
    –name n8n \
    -p 5678:5678 \
    -e N8N_HOST=mydomain.com \
    -e WEBHOOK_URL=https://mydomain.com \
    -e VUE_APP_URL=https://mydomain.com \
    -v n8n_data:/home/node/.n8n \
    docker.n8n.io/n8nio/n8n

Fixing Google OAuth Redirect URI Errors

  1. Go to Google Cloud Console
  2. Edit your OAuth 2.0 Client ID
  3. Add the following to Authorized Redirect URIs:
https://mydomain.com/rest/oauth2-credential/callback

If you don’t add this, Google will throw redirect_uri_mismatch errors.

Testing Your Setup

After completing all the above steps:

  • Visit https://mydomain.com — you should see the n8n UI
  • Try to connect a Google credential

Complete OAuth and see it redirect back to your domain (not localhost!)

Automating Everything with docker-compose

You can simplify the entire flow by putting your n8n instance into the same docker-compose.yml file and using the depends_on flag.

This allows you to:

  • Restart all containers easily
  • Manage all services in one place
  • Mount certs directly from shared volumes

Let me know if you want a full compose setup including n8n.

MistakeFix
localhost
in OAuth callback
Set
WEBHOOK_URL
and
VUE_APP_URL
to your domain
Certbot 404 during challenge
Ensure nginx is serving
/.well-known/… 
correctly
Docker network errors
Use
docker network create nginx-net
Port already in use
Use
docker ps
and
docker rm -f <container>
to clear




🌟Conclusion and Deployment Tips


You’ve just:
  • Set up n8n with a real public domain
  • Secured it using free SSL certs
  • Fixed Google OAuth integration
  • Dockerized the full reverse proxy and automation stack
This setup can be reused for any microservice needing:
  • Secure HTTPS hosting
  • OAuth integrations
  • Dockerized deployment

Mayurkumar Patel

Mayurkumar is a Software Architect and an Engineer whose passion is to challenge real-world problems using technology. He has lent his expertise to great organizations like Tata Consultancy Services, Balance IT, Zipcar, Gobble, Fitard, and more. He excels in Agile Project Management, Designing & Architecture of Software, and leads his teams to transform ideas into real products. He is also an ace at setting up the Modern Cloud Infrastructure and maintaining the same.


Leave a Reply

Your email address will not be published. Required fields are marked *