Home > other >  Hosting a custom domain website in Raspberry Pi
Hosting a custom domain website in Raspberry Pi

Time:11-08

I made a dynamic nextjs website and everything worked as my expectations, but I can't figure out how to host it on my raspberry pi 4. I own SSL certificate and a DNS that I want to use. I would gladly accept any kind of answer that might include thirdparty web services or software such as Docker, AWS, or Replit if there is no answer.

CodePudding user response:

There are a few ways to do this, but the most straightforward way would be to use a reverse proxy. This would allow you to host your Next.js website on your Raspberry Pi, while still being able to access it via a domain name or subdomain.

To set up a reverse proxy, you would first need to install a web server on your Raspberry Pi. The most popular choice for this would be Nginx. Once Nginx is installed, you would then need to configure it to act as a reverse proxy for your Next.js website. The final step would be to point your domain name or subdomain to your Raspberry Pi's IP address.

  1. Set up a Raspberry Pi as a web server using a reverse proxy.

  2. Install NGINX:

sudo apt update
sudo apt install nginx
  1. Configure NGINX as a reverse proxy:
sudo nano /etc/nginx/sites-available/default
  1. Add the following lines to the end of the file:
server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}
  1. Save the file and exit.
  2. Enable the new configuration:
sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/
  1. Restart NGINX:
sudo systemctl restart nginx
  1. Configure an A Record for your domain to point to the IP address of your Raspberry Pi.
  • Related