2

I'm using Nginx repository to make and make install Nginx from source on server. But in some articles they ran apt install nginx at least! My steps:

 wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \
    tar xzf /usr/src/nginx-${NGINX_VERSION}.tar.gz

And then:

cd /usr/src/nginx-${NGINX_VERSION} && \
    ./configure \
    --prefix=/etc/nginx \
    --sbin-path=/usr/bin/nginx \
    --conf-path=/etc/nginx/nginx.conf \
    --error-log-path=/var/log/nginx/error.log \
    --http-log-path=/var/log/nginx/access.log \
    --add-module=/usr/src/nginx-modules/incubator-pagespeed-ngx-${NPS_VERSION}-stable \
    --with-pcre \
    --pid-path=/var/run/nginx.pid \
    --with-http_ssl_module \
    --user=nginx \
    --group=nginx \
    --with-http_gunzip_module \
    --with-http_gzip_static_module \
    --with-http_v2_module \
    --with-http_flv_module \
    --with-http_mp4_module \
    --with-compat \
    --with-http_slice_module \
    --with-stream_ssl_module \
    --modules-path=/usr/lib/nginx/modules

and run

make && make install

Define a user:

  adduser --system --no-create-home --shell /bin/false --group --disabled-login nginx

Till now everything is perfect. In my case before install the nginx from package manager my nginx version was 1.23.1 (stable version) and after install it from package manager apt install nginx it goes (1.18)

  1. Why we need to install Nginx from package managers(like apt in this case) when we did it from source?
  2. How can I set some specific options when I use package manager to install the Nginx?
rfatolahzade
  • 103
  • 9

1 Answers1

1

Nginx maintenairs publish compiled nginx binaries with some predefined options. https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#prebuilt

Those binaries may not fit for everyone or every usage. One can compile nginx from source code and use it as you do.

But in some articles they ran apt install nginx at least!

Tutorials does not tend to complicate the learning process.

Why we need to install Nginx from package managers (like apt in this case) when we did it from source?

You don't have to use any package manager at all. But if you install nginx by using apt it will try to remove your custom binary. This is why you get a different nginx version.

How can I set some specific options when I use package manager to install the Nginx?

Nginx has mainline and stable binaries published at different repositories. Mainline - Includes the latest features and bug fixes and is always up to date.

https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#installing-a-prebuilt-ubuntu-package-from-the-official-nginx-repository

You can specify a package version when using apt

apt update
apt list -a nginx
apt install nginx=<specific-version...>

https://askubuntu.com/questions/92019/how-to-install-specific-ubuntu-packages-with-exact-version

nginx -V shows a nginx binary's configure arguments. You may use it to compile your custom nginx binary.

Hope, this helps.

ocos
  • 1,901
  • 1
  • 10
  • 12
  • Thanks for reply <3 I've got your answer and I appreciate that. About `How can I set some specific options when I use package manager to install the Nginx?` let me clear it, consider it I wanna just use `apt` to install Nginx, how can I (for a example on installing step) set Nginx user(not default-and just on installing step) or add some module which doesn't exist in the default installation of the Nginx like zlib or other non-default options (not Dynamic Modules) ? – rfatolahzade Feb 03 '23 at 13:52
  • I should install it just via `apt install nginx` and then change the nginx.conf for user or add load_module (after aim them) in the config? Such as for zlib: `wget http://zlib.net/zlib-1.2.13.tar.gz tar -zxf zlib-1.2.13.tar.gz cd zlib-1.2.13 ./configure make sudo make install` And then add load_module modules/zlibthings.so; ? and some cases I should turn them on and set specific values. – rfatolahzade Feb 03 '23 at 14:04
  • 1
    You may have some conflicts when mixing official nginx binaries with custom configured modules. However, if your server configuration is similar to official build environment, it may work for some modules. I prefer to use official binaries or custom made ones but not the same time. You want to add/remove/edit some modules etc to your nginx installation/configuration. If it is for a CI/CD work, you may write some installation script for each scenario. And compiling from source code may be more suitable for your requirements than installing from apt. Maybe, another user can answer this question. – ocos Feb 03 '23 at 14:42
  • Thank you for your comment. I've got it and did it in my server just via source. thanks – rfatolahzade Feb 04 '23 at 10:54