This post is about Installing Nginx on OpenBSD 7.1
Introduction to Nginx
Nginx is a web server created with a focus on performance, high concurrency and low resource usage. It serves the majority of the top websites. Whilst this is mostly due to its performance, it’s also relatively easy to get started with.
By default, Nginx deals with web requests asynchronously i.e. a single nginx process can serve multiple requests concurrently. However, because of this design Nginx, as compared to web servers like Apache, can’t embed server side programming languages like PHP into its own process. This means those tasks are to be handled by completely separate processes and then reverse proxied back to the clients via Nginx. Therefore, at its core, Nginx is actually just a reverse proxy.
In this article, we’re going to go through the process of compiling and installing Nginx through source. While installation through the package manager is fairly easy, we do not get as much control over the Nginx binary as we get by compiling from source. I have chosen OpenBSD for it serves very well as a secure server operating system.
Installing Nginx on OpenBSD 7.1
Nginx has two websites: nginx.org and nginx.com. nginx.org is where we’ll look most of the time for documentation, etc. with nginx.com being the commercial “nginx as a product” side.
To download nginx, we’ll head over to the download sitem and fetch the latest mainline version.
We can now extract the compressed tarball.
Compiling
Now we need to run the configure
script. This is where the control we get from building from source really shines. The configure options are well documented. For now, I am going with the following command-line:
./configure --sbin-path=/usr/local/bin/nginx \
--conf-path=/usr/local/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-threads --with-http_ssl_module --with-http_v2_module \
--with-http_gzip_static_module --with-http_gunzip_module \
--with-http_auth_request_module --with-http_secure_link_module \
--with-http_stub_status_module --without-mail_imap_module \
--without-mail_smtp_module --without-mail_pop3_module \
--with-pcre --with-pcre-jit \
--with-cc-opt='-Ofast -fstack-protector-strong'
Finally, let’s go ahead and compile the source with make install
as root.
Basic Configuration
Nginx has it own set of terminologies which are used in various files. If you’re unfamiliar with them, then this guide should serve you well. For now, we’ll proceed with a basic configuration. Note that the events
context should exists even if it’s empty.
We can check the configuration syntax with nginx -t
. Now that we’re done with the configuration, we can start nginx. For now, I’ll just use the same binary with no flags (i.e. just nginx
) for starting the daemon.
This shows that our nginx installation is working. We’ll eventually have to use the rc scripts for managing the daemon. I also intend to cover some advanced topics, hopefully in the later articles. Nevertheless, that’s it for this article. Thank you for reading.
I think you have to remove the –with-pcre-jit build option as pcre JIT is not supported on OpenBSD.
Why are you compiling nginx from source rather than using OpenBSD port/package? Missing out on some of the advantages, such is the chroot(2) support OOTB.