Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Building Nginx from Source for Static File Hosting on Ubuntu

Tech 1

To compile Nginx on Ubuntu for serving static content, first install the toolchain and required libraries:

sudo apt update
sudo apt install -y build-essential libpcre3-dev zlib1g-dev libssl-dev

The build environment requires PCRE for regex support in location blocks, zlib for gzip compression modules, and OpenSSL for TLS termination capabilities.

Download the Nginx source distribution and extract the archive. Navigate to the extracted directory and configure the build parameters:

./configure --prefix=/opt/nginx --with-http_ssl_module --with-http_gzip_static_module
make
sudo make install

The installation creates the following hierarchy under /opt/nginx:

  • conf/ - Configuration files including nginx.conf
  • html/ - Default web root for static assets
  • logs/ - Access and error log files
  • sbin/ - Binary executables

Launch the server by executing the binary directly:

sudo /opt/nginx/sbin/nginx

Validate the installation by querying the process status:

pgrep -a nginx

For lifecycle management, use these signal-based commnads:

# Graceful shutdown
sudo /opt/nginx/sbin/nginx -s quit

# Immediate termination
sudo /opt/nginx/sbin/nginx -s stop

# Configuration reload without dropping connections
sudo /opt/nginx/sbin/nginx -s reload

Configure static resource delivery by modifying /opt/nginx/conf/nginx.conf. Place assets in the designated document root directory. Ensure the worker process has read permissions on all static files and directories.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.