在Ubuntu上离线安装Nginx的踩坑经历

3 篇文章 0 订阅

前言

简单记录一下如何在Ubuntu上离线安装Nginx的过程。像这种传统安装挺复杂的,最好还是用Docker安装吧。

Nginx官网:http://nginx.org/download/

一、第一次安装Nginx 

(1)首先任意下载一个较新稳定版本

(2)解压

tar -zxvf nginx-1.17.8.tar.gz

(3)进入目录

cd nginx-1.17.8

(4)选择安装目录和配置选项

./configure \
--prefix=/usr/local/nginx-1.17.8 \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--user=nginx \
--group=nginx \
--with-pcre \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module

二、出现缺少PCRE依赖库问题

(1)无意外的话是正常安装了,但也有个别情况,出现了【error: the HTTP rewrite module requires the PCRE library】错误。网上解决方案是:

sudo apt-get update
sudo apt-get install libpcre3 libpcre3-dev

(2)但是也有安装不成功的时候,之后还使用了【apt-get】的命令安装Nginx也装不成功:

apt-get install nginx

(3)无奈只能根据提示自行安装PCRE,PCRE的官网地址:http://www.pcre.org,在官网可以找到其在github的下载地址:https://github.com/PhilipHazel/pcre2/releases,于是下载了【pcre2-10.38.tar.gz】

三、安装PCRE依赖库

(1)解压

tar -zxvf pcre2-10.38.tar.gz

(2)进入目录

cd pcre2-10.38

(3)选择安装目录

./configure --prefix=/usr/local/pcre2-10.38

(4)编译

make

(5)安装

make install

四、第二次安装Nginx

(1)安装成功之后,重新进入nginx解压包目录下,根据错误信息,需要增加参数,指定PCRE依赖库的路经地址【--with-pcre \】改成【--with-pcre=../pcre2-10.38 \】,注意要写成与nginx安装目录的相对路径,不然报另一个错,又得重新执行选择安装目录命令了。

cd nginx-1.17.8

(2)选择安装目录和配置选项

./configure \
--prefix=/usr/local/nginx-1.17.8 \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--user=nginx \
--group=nginx \
--with-pcre=../pcre2-10.38 \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module

(3)编译

make

(4)这时出现了【fatal error: pcre.h: No such file or directory】错误,原来是下错了PCRE版本

 (5)正确的PCRE下载地址为以下链接,于是下载了【pcre-8.35.tar.gz】

PCRE - Browse /pcre at SourceForge.netPERL 5 regular expression pattern matchingicon-default.png?t=N7T8https://sourceforge.net/projects/pcre/files/pcre/

五、再次安装PCRE依赖库

(1)解压

tar -zxvf pcre-8.35.tar.gz

(2)进入目录

cd pcre-8.35

(3)配置

./configure

(4)编译

make

(5)安装

make install

六、第三次安装Nginx

(1)安装成功之后,重新进入nginx解压包目录下,根据错误信息,需要增加参数,指定PCRE依赖库的路经地址【--with-pcre \】改成【--with-pcre=../pcre-8.35 \

cd nginx-1.17.8

(2)选择安装目录和配置选项 

./configure \
--prefix=/usr/local/nginx-1.17.8 \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/tmp/nginx/client \
--http-proxy-temp-path=/var/tmp/nginx/proxy \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--user=nginx \
--group=nginx \
--with-pcre=../pcre-8.35 \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-http_v2_module \
--with-threads \
--with-stream \
--with-stream_ssl_module

 (3)编译,此时可以正确编译了

make

(4)安装

make install

(5)验证安装成功

nginx -v

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
你可以按照以下步骤在 Ubuntu 20.04 上离线安装 Nginx: 1. 在一台可以连接互联网的机器上下载 Nginx 的安装包和依赖包。你可以在 Nginx 的官方网站(https://nginx.org/en/download.html)上找到适合你的操作系统版本的安装包。 2. 将下载好的安装包和依赖包复制到目标机器上,可以使用 USB 驱动器、网络共享等方式进行传输。 3. 在目标机器上打开终端,并切换到保存了安装包的目录。 4. 解压 Nginx 安装包,可以使用以下命令(假设安装包名为 nginx.tar.gz): ``` tar -zxvf nginx.tar.gz ``` 5. 进入解压后的目录: ``` cd nginx-<version> ``` 注意替换 `<version>` 为你下载的 Nginx 版本号。 6. 安装 Nginx 的依赖包。如果你已经下载了依赖包,可以使用以下命令安装: ``` sudo apt-get install -y <dependency-package1> <dependency-package2> ... ``` 注意将 `<dependency-package1>`, `<dependency-package2>` 等替换为你下载的依赖包的名称。 7. 运行配置脚本,生成编译配置: ``` ./configure ``` 8. 编译 Nginx: ``` make ``` 9. 安装 Nginx: ``` sudo make install ``` 10. 安装完成后,你可以使用以下命令启动 Nginx: ``` sudo nginx ``` Nginx 默认会监听 80 端口,你可以在浏览器中访问服务器的 IP 地址来验证是否安装成功。 这样就完成了 Ubuntu 20.04 上离线安装 Nginx 的步骤。希望对你有帮助!如果你有任何问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值