Run a Live Website in Termux Using Nginx! 🚀

Host a highly customizable web server on termux 📲. The web is fueled by servers, and Nginx is one of the most powerful and lightweight options out there! 🎉 Whether you're testing websites or hosting your projects locally, you can create a fully functional Nginx web server in Termux. In this post, I’ll guide you through installing, running, and making your website live in Termux using Piggy for port forwarding. Let's get started! 🔥


🔍 What is Nginx?  

Nginx (pronounced Engine-X) is an open-source web server software designed for high performance and scalability. It’s widely used for hosting websites, acting as a reverse proxy, load balancing, and more. If you’re experimenting with servers in Termux, Nginx is a must-have tool.  


With Termux + Nginx, you can:  

- Host your own website locally.

- Learn and practice web development.  

- Make your site live using port forwarding.  



🛠️ Install Nginx in Termux  

Installing Nginx in Termux is super simple. It’s available in the Termux package repository, and you can get it with one command:  

pkg install nginx && pkg install termux-services

Once installed, the Nginx server files will be available in the

/data/data/com.termux/files/usr/share/nginx/ directory.  I have also added the command to install termux-services so we can manage nginx services with sv command.


🚀 Run Nginx in Termux  

Let’s fire up your Nginx server:  

Step 1: Start the Nginx Service  

Type the following command to start the Nginx server:  

sv up nginx

This will start the Nginx service and make it accessible on your **localhost:8080**.  


Step 2: Check If Nginx Is Running  

Open your browser and type:  

http://localhost:8080

You should see the default Nginx welcome page that says "Welcome to Nginx."  

If this works, it means your server is running properly. 🎉  


Step 3: Stop the Nginx Service

If you want to stop your Nginx server, you can use this command:

sv down nginx

Stopping the service will make your server unavailable until you restart it.



✏️ Edit Nginx Web Pages  

The default HTML page served by Nginx is located in:  

/data/data/com.termux/files/usr/share/nginx/html

To edit the default page:  


Step 1: Navigate to the Nginx Directory   

cd $PREFIX/share/nginx/html


Step 2: Open the HTML File

Install a text editor like Nano if you don’t have it already:  

pkg install nano

Now, open the file:  

nano index.html


Step 3: Modify the HTML Code

Change the text `"Welcome to Nginx!"` to something like `"Welcome to My Cool Website!"`.  

Press `CTRL + S` to save and `CTRL + X` to exit.  


Step 4: Refresh Your Browser

Reload http://localhost:8080 in your browser, and you should see your changes live! 🚀  


🌐 Make Your Website Live Using Piggy  

To make your website accessible to others online, we’ll use Piggy for port forwarding. This tool lets you expose your local server to the internet.  

Step 1: Install openssh

It's just a package and you can install it with:

pkg install openssh

 

Step 2: Run Piggy  

Start Piggy and forward the Nginx port (8080):  

ssh -p 443 -R0:localhost:8081 a.pinggy.io

Piggy will provide you with a public URL like:  

https://12345.piggyserver.com

Share this URL with your friends or use it for testing. 🎉  


💡 Add Your Own Web Pages  

You can create your own web pages and serve them using Nginx:  

Step 1: Create a New HTML File  

Navigate to the htdocs folder:  

cd $PREFIX/share/nginx/html

Create a new file:  

nano about.html

Write your HTML code and save it.  


Step 2: Access Your Page

Visit the new page by typing this in your browser

http://localhost:8080/about.html

You can add multiple pages, link them together, and even build a full website!  



Conclusion:

Nginx is an amazing tool to turn your Termux into a powerful server. Whether you’re practicing HTML, hosting a project, or learning about web servers, this guide should help you get started. Try building a mini-site with multiple pages, use Piggy to share it online, and unleash your creativity! 🌐✨ Stay curious, stay inspired, and as always, stay ethical! 👾

Post a Comment

0 Comments

Popup Image