For the complete documentation index, see llms.txt. This page is also available as Markdown.

38.2 Nginx Web Server

Nginx employs an event-driven asynchronous architecture with a multi-process single-threaded worker model, achieving high concurrency handling with low memory consumption. This section covers installation via pkg and basic configuration.

Installing Nginx

Install Nginx using the pkg package manager:

# pkg install nginx

Install Nginx using Ports:

# cd /usr/ports/www/nginx/
# make install clean

In addition to the main program, the system provides multiple Nginx-related packages, which can be retrieved in the following ways.

Use the pkg command to quickly search for Nginx-related packages:

$ pkg search -o nginx

You can also find Nginx-related packages in the Ports directory; this method is suitable for scenarios where you need to view the source code:

$ ls /usr/ports/www/ | grep nginx

Daemon

To ensure Nginx starts automatically at boot, first configure it as an enabled service, then manually start the service for testing.

Set the Nginx service to start automatically at system boot:

Start the Nginx service; the system will automatically check the configuration file syntax before starting:

You can use the following command to view the IPv4 network connections and ports that Nginx is listening on; this method effectively verifies the service running status:

Browsing Web Pages

After confirming that the Nginx service is running normally, you can verify the web server through a browser.

Open localhost in the local browser, or access using the server IP address, for example http://192.168.179.150/:

Tip

The 192.168.179.150 in the above example is a placeholder and needs to be replaced with the actual value.

Nginx FreeBSD

Configuration Files

Nginx configuration is flexible, employing a modular structural design; for detailed configuration methods, please refer to the official documentation. This section only briefly explains how to start Nginx on FreeBSD and the location and usage of its configuration files.

For configuration tutorials, please refer to the official documentation.

On FreeBSD, Nginx configuration files are located in the /usr/local/etc/nginx/ directory, with the main configuration file being /usr/local/etc/nginx/nginx.conf, which is organized in a hierarchical structure.

Directory structure:

In the default configuration, the Nginx site root directory is /usr/local/www/nginx/. To change the site root directory, in the /usr/local/etc/nginx/nginx.conf file, change

to the actual directory path needed, for example root /path/to/new/webroot;. After modifying the configuration, you need to restart the service for changes to take effect.

Sample Configuration File (Nginx + Typecho Pseudo-static + SSL)

To facilitate understanding of Nginx configuration, the following provides a complete sample configuration file, including Nginx, Typecho pseudo-static rules, and SSL configuration.

References

  • FreeBSD Project. nginx -- HTTP and reverse proxy server, mail proxy server[EB/OL]. [2026-04-14]. https://man.freebsd.org/cgi/man.cgi?query=nginx&sektion=8. Nginx server manual page, describing startup options and signal handling.

  • Nginx, Inc. Nginx Documentation[EB/OL]. [2026-04-14]. https://nginx.org/en/docs/. Official Nginx documentation, covering configuration directives, modules, and performance tuning.

Last updated