To begin the installation process for NGinx on FreeBSD, follow these steps:

  1. Install PCRE (Perl Compatible Regular Expressions) by running the following command:
pkg_add pcre

When we haven’t pcre on our system, we will get the following error:

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
  1. Proceed to install wget using the following command:
pkg_add wget
  1. Download the NGinx source code from the official website. Use the wget command to retrieve the source code file:
  1. Extract the downloaded file using the following command:
tar xzvf nginx-1.17.0.tar.gz
  1. Configure the Makefile for NGinx by navigating into the extracted directory and running the configure script with the desired parameters:
cd nginx-1.17.0
./configure --sbin-path=/usr/local/sbin/nginx \
              --conf-path=/etc/nginx/nginx.conf \
              --pid-path=/var/run/ \
              --with-http_ssl_module \
              --http-log-path=/var/log/nginx.log \
              --error-log-path=/var/log/nginx-error.log \
              --http-fastcgi-temp-path=/var/tmp/fastcgi_tmp \
              --http-proxy-temp-path=/var/tmp/proxy_tmp \
              --http-client-body-temp-path=/var/tmp/client_body_temp \
              --with-http_stub_status_module \
              --user=www --group=www
  1. Proceed to compile and install NGinx by running the following commands:
make && make install
  1. Once the installation is complete, start NGinx using the following command:

If you need to restart NGinx at any point, use the following command:

kill -HUP $(head -1 /var/run/

To stop NGinx, execute the following command:

kill -QUIT $(cat /var/run/

Adding service

To ensure NGinx starts automatically on system boot and can be managed as a service, you can add it to the FreeBSD service management system. Follow these steps:

  1. Create a file named nginx in the /usr/local/etc/rc.d/ directory. Use the following command to create the file
vi /usr/local/etc/rc.d/nginx

and put following content on it:


# PROVIDE: nginx
# REQUIRE: LOGIN cleanvar
# KEYWORD: shutdown

. /etc/rc.subr



load_rc_config $name

# NGinx binary path

# NGinx configuration file

# NGinx PID file


command_args="-r -P $nginx_pid $nginx_bin -c $nginx_conf"

    ${command} ${command_args}

    kill -QUIT $(cat $nginx_pid)

    kill -HUP $(cat $nginx_pid)

run_rc_command "$1"
  1. Enable service
sysrc nginx_enable=YES
  1. Start nginx
service nginx start

To stop, start and reload service use the following commands:

service nginx start
service nginx stop
service nginx reload