How to Install Nginx on a FreeBSD Cloud Server?

01-02-2024 01:59:49

Updating FreeBSD

For a freshly installed FreeBSD operating system, it's usually necessary to install the Port Tree. If the Port Tree has already been installed, it also needs to be updated. Execute the following command to install or update the Port Tree. Simply put, a Port is a piece of software that has been ported to FreeBSD.

portsnap fetch extract

To install the most recently downloaded Port software, it's also necessary to update the package manager (pkg). Execute the command below to update pkg.

cd /usr/ports/ports-mgmt/pkg
make reinstall
make clean

Installing Nginx

Similar to the previous step, execute the following commands to set up the Nginx components to be installed.

cd /usr/ports/www/nginx
make config-recursive

The system will prompt for the selection of components such as HTTP_GZIP_STATIC, HTTP_SSL, HTTP_DAV_EXT, etc., with subsequent prompts being the default options. After the selection is complete, execute the commands for Nginx installation and cleanup.

make install
make clean

Next, set up Nginx to start automatically with the system. Edit the /etc/rc.conf file and add the following line at the end of the file:

nginx_enable="YES

Then, start Nginx.

service nginx start

Finally, access the IP address in a web browser to test if the "Welcome to Nginx!" page displays correctly.