How to Change Default Index Page on Nginx

In this tutorial you will learn how to change the default index page after installing nginx. When you install nginx, the default page is a simple index html file that says " Welcome to Nginx" . This page can be easily changed/replaced with anything you want.

If you want to change this file, you can do so by following the steps in this tutorial



Where is the index file located?

The index file is located on /var/www/html to change this file you can replace it with your own index.html file, or simply edit the current one by using any text editor or any other file transfer software, for example you can make changes directly from your server by using Filezilla without having to replace the index.html file.

This procedure is faster, however this depends on the type of file or website that you are trying to create.

Step 1 - Login to your Server

Login to your server via SSH

ssh user@ip

Step 2 - Go to Html Directory

Next go to the html directory where the index file is located, browse into the html directory by using the cd command

cd /var/www/html

Once you are inside the html directory, there are multiple ways to change or edit this file.

1)You can edit the index file directly from the terminal by using any text editor such as : nano or vim

sudo nano index.html

Once you are done with the changes, press CTRL + X to save changes.

2) Uploading the file(s) via FTP/SFTP

To do this you can add your server to Filezilla and connect to it using the sftp protocol, then simply browse to the same path as shown above and then simply upload your files.

Host - Put your Server's IP

Username - Your username

Password - Your Password

Port - In this case we are using sftp protocol so the port is 22, then click Quickconnect button to login to your server

As shown in the screenshot below, make sure you are in the directory - /var/www/html, then drag and drop files you want to upload into this directory.

For example: If you have an HTML template that contains multiple folders such as: css, js, images and index.html file then you have to make sure you upload everything into /var/www/html

3) You can also use FTP protocol to upload files with Filezilla, all you need to do is change the 22 port to the FTP port (21) and then click the quickconnect button.

The difference between SSH and FTP is that, SSH is secure and all data you transfer via SSH is encrypted, FTP on the other hand is not secure and it allows only file transferring.

I wouldn't recommend using FTP instead of SSH, however if you don't have access to SSH then FTP might be the only way.

However, depending on the hosting company most of companies allow ssh access if you are using paid hosting, there are also some companies which don't allow ssh access by default but you have to contact them in order to enable it for you.

Personally I'd recommend you a VPS and save yourself from the struggle of going through support to ask for ssh access to be allowed, also no matter what type of paid hosting you use, you will never have full access like you do when you have your own VPS.

⁉️
Did you know?

You can get $20 free cloud credit on Hetzner if you join via our link

https://hetzner.cloud/?ref=m4JUULSLJowC

Step 3 - Restart Nginx

If you still see the default page even after editing or replacing it, clear your browser's cache, then restart nginx and try again.

sudo systemctl restart nginx

Once Nginx has been restarted you should see the updated content on your website

Conclusion

In this tutorial you learned where the default Nginx page is located, and how to change it by using any text editor or by simply using an software like Filezilla.

Author

Comments