Site icon JnPnote

How to Create Subdomain in Raspberry Pi

I have Raspberry Pi 2 from my friend, and set it up already. I haven’t write post for setting up the RPi, but there are tons of tutorials. You can refer to them to setup the RPi.

In this post I will write how to configure Nginx for new subdomain for myself to remember.

1. Prerequisites

2. Create New sites-available

First, let’s see what you have on your rpi. cd /etc/nginx/sites-available then ls to see what you have there.

In my case, I have default and jisoo. Now, I will create new one for new domain. It would be better to copy the default or already existing one, so you don’t have to write the whole configuration.

sudo cp default my-app

default can be replaced with whatever you have, and my-app can be replaced with whatever you want to call for new file/subdomain name. my case, I do sudo cp jisoo practice

Now, sudo nano practice, in my case, and edit the configuration. There are only two things to edit. the root and the server_name.

ctrl+o to save the file and ctrl+x to exit the nano.

3. Create a symlink in the sites-enabled

Most of tutorials I have searched didn’t do this, but I guess this needs to be done to enable the configuration in sites-available. And actually, I have tested without a symlink created, and it was not working. so… run below command to create a symlink.

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

You need to replace practice to whatever your folder name.

Then, reload the nginx by either sudo systemctl reload nginx or sudo service nginx reload

4. Create the Root Folder

Create new folder for the targeted root folder.

5. Deploy to RPi

Now, you can deploy your project to RPi. In case, you created react project for test, you can easily just copy paste the build folder using scp command. See Deploy to RPi without using git

That’s it! I can see the new site running fine! 🙂

Exit mobile version