The NGINX HTTP web server is one of the most popular alternatives to Apache while aiming to be highly configurable, flexible, and performant. It also has a lot of support, being backed by F5 on top of having great documentation.
The nginx daemon is ran by the root user, but
subprocesses are ran as a regular user and group, which must be created.
Create the following group and user using the following commands as the
root user:
groupadd -g 25 nginx &&
useradd -c "NGINX Web Server" -g nginx \
-s /bin/false -u 25 nginxInstall NGINX by running the following commands:
./configure --prefix=/etc/nginx \
--conf-path=/etc/nginx/nginx.conf \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--pid-path=/run/nginx.pid \
--lock-path=/run/lock/nginx.lock \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=stderr \
--http-client-body-temp-path=/var/lib/nginx/client-body \
--http-proxy-temp-path=/var/lib/nginx/proxy \
--http-fastcgi-temp-path=/var/lib/nginx/fastcgi \
--http-scgi-temp-path=/var/lib/nginx/scgi \
--http-uwsgi-temp-path=/var/lib/nginx/uwsgi \
--user=nginx \
--group=nginx \
--with-compat \
--with-threads \
--with-pcre-jit \
--with-file-aio \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_degradation_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_perl_module=dynamic \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-http_v3_module \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-stream_ssl_preread_module &&
make
If the source was cloned and not obtained via the tarball, the configure
script will be at auto/configure.
Now, as the root user:
make install && mkdir -pv /var/lib/nginx && install -vDm644 man/nginx.8 -t /usr/share/man/man8/
--prefix=/etc/nginx: Unlike other package builds
that set the prefix to /usr, this
prefix is set differently so all the configuration files are placed and
checked in a sane directory structure/location.
--conf-path=/etc/nginx/nginx.conf This parameter
ensures the main NGINX daemon configuration file is in /etc/nginx.
--sbin-path=/usr/sbin/nginx: This parameter
ensures that nginx does not get installed in /etc.
--http-*-path=*: These parameters ensure the
temporary NGINX state directories and logging are in sane places.
--{user,group}=nginx: These parameters hand off
subprocess reponsibilities to the nginx user and
group. If these aren't specified, the respective values would be
nobody and nogroup.
--with-*_module{,=dynamic}: These parameters
build modules that aren't enabled by default that can be really useful.
Those that can be built dynamically are. Most cannot be.
Most of the configuration is done in
/etc/nginx/nginx.conf. Paths to content which will
be served aren't hardcoded, and you can specify where important HTML
files are. You should read the NGINX beginner's
guide to learn how to configure the NGINX daemon.
If you want Apache-styled per-user handling of HTML paths, you can do
something like this in /etc/nginx/nginx.conf:
server {
location ~ ^/~(.+?)(/.*)?$ {
alias /home/$1/public_html$2;
index index.html index.htm;
autoindex on;
}
}