在ubuntu22.04.1上从源代码安装Nginx,然后使用包管理器

wlp8pajw  于 2023-02-07  发布在  Nginx
关注(0)|答案(1)|浏览(235)

我正在使用Nginx存储库从服务器上的源代码制作和安装Nginx。但在一些文章中,他们至少运行apt install nginx!我的步骤:

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

然后:

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

并运行

make && make install

定义用户:

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

到目前为止一切都很完美。在我的情况下,在从包管理器安装nginx之前,我的nginx版本是1. 23. 1(稳定版本),在从包管理器apt install nginx安装之后,它变成了(1. 18)
1.当我们从源代码安装Nginx时,为什么我们需要从包管理器(如本例中的apt)安装它?
1.当我使用软件包管理器安装Nginx时,如何设置一些特定的选项?

mspsb9vt

mspsb9vt1#

Nginx maintenairs发布带有一些预定义选项的编译后的nginx二进制文件。https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#prebuilt
这些二进制文件可能不适合每个人或每个用途。人们可以从源代码编译nginx并像你一样使用它。
但在一些文章中,他们至少运行apt install nginx
教程不会使学习过程复杂化。
当我们从源代码安装Nginx时,为什么我们需要从包管理器(如本例中的apt)安装它?
你根本不需要使用任何软件包管理器,但是如果你使用apt安装nginx,它会试图删除你的自定义二进制文件,这就是为什么你会得到一个不同的nginx版本。
当我使用软件包管理器安装Nginx时,如何设置一些特定的选项?
Nginx在不同的存储库中发布了mainlinestable二进制文件。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
使用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显示了一个nginx二进制文件的配置参数。你可以用它来编译你定制的nginx二进制文件。
霍普,这个有用

相关问题