Back to course

Deploying a Static Site (Apache/Nginx alternatives in Termux)

Termux Masterclass: From Zero to Linux Power User on Android

44. Deploying a Static Site (Apache/Nginx alternatives in Termux)

While Python's server is great for testing, Termux offers actual web server packages like nginx and apache2 for more complex or production-like environments.

Option 1: Using Nginx (Lighter and Faster)

Nginx is often preferred for serving static content due to its efficiency.

  1. Installation: bash $ pkg install nginx

  2. Configuration: Nginx configuration files are typically located in /data/data/com.termux/files/usr/etc/nginx/. You need to edit the nginx.conf file to define your server block and specify your site's root directory (e.g., ~/webroot).

  3. Starting Nginx: bash $ nginx

    By default, Nginx listens on port 8080 (as standard ports below 1024 are restricted in Termux).

Option 2: Using Apache HTTP Server

Apache is heavier but provides features like .htaccess files.

  1. Installation: bash $ pkg install apache2

  2. Starting Apache: bash $ apachectl start

Apache usually serves content from /data/data/com.termux/files/usr/share/apache2/default_site/ and runs on port 8080.

Important Considerations

Running a production web server on Termux requires the application to stay active, potentially draining the battery. These setups are best suited for local development, testing, and educational purposes.