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

简介: 本文记录了作者在Ubuntu系统上离线安装Nginx的详细过程,包括下载、配置、解决依赖问题、编译和安装步骤,以及在安装过程中遇到的PCRE库依赖问题和解决方案。

前言

简单记录一下如何在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
目录
相关文章
|
15天前
|
Ubuntu Unix 应用服务中间件
Ubuntu16.04.1 安装Nginx
Ubuntu16.04.1 安装Nginx
|
4月前
|
Ubuntu 前端开发 JavaScript
技术笔记:Ubuntu:一个部署好的tomcat应用(war包)怎么用Nginx实现动静分离?
技术笔记:Ubuntu:一个部署好的tomcat应用(war包)怎么用Nginx实现动静分离?
|
2月前
|
存储 Ubuntu 应用服务中间件
如何在 Ubuntu VPS 上配置 Nginx 的日志记录和日志轮转
如何在 Ubuntu VPS 上配置 Nginx 的日志记录和日志轮转
27 4
|
2月前
|
Ubuntu 搜索推荐 应用服务中间件
如何在 Ubuntu 14.04 上配置 Nginx 使用自定义错误页面
如何在 Ubuntu 14.04 上配置 Nginx 使用自定义错误页面
46 2
|
2月前
|
关系型数据库 应用服务中间件 PHP
如何在 Ubuntu 16.04 上使用 Nginx 部署 Laravel 应用
如何在 Ubuntu 16.04 上使用 Nginx 部署 Laravel 应用
29 1
|
2月前
|
缓存 Ubuntu 前端开发
在Ubuntu上手动与自动启动Nginx的踩坑经历、以及重启服务
本文分享了作者在Ubuntu系统上手动和自动启动Nginx服务的踩坑经历,包括创建启动脚本、解决依赖问题、配置服务自动启动以及通过命令行管理Nginx服务的方法。
280 0
在Ubuntu上手动与自动启动Nginx的踩坑经历、以及重启服务
|
2月前
|
关系型数据库 MySQL 应用服务中间件
在Ubuntu 16.04上使用Nginx安装和保护phpMyAdmin的方法
在Ubuntu 16.04上使用Nginx安装和保护phpMyAdmin的方法
27 0
|
2月前
|
关系型数据库 Linux 应用服务中间件
如何在 Ubuntu 14.04 服务器上使用 Nginx 安装和保护 phpMyAdmin
如何在 Ubuntu 14.04 服务器上使用 Nginx 安装和保护 phpMyAdmin
20 0
|
2月前
|
Ubuntu 应用服务中间件 Linux
如何在Ubuntu 14.04上使用Nginx和Php-fpm安全地托管多个网站
如何在Ubuntu 14.04上使用Nginx和Php-fpm安全地托管多个网站
22 0
|
2月前
|
缓存 Ubuntu 应用服务中间件
如何在 Ubuntu 14.04 上使用 Passenger 和 Nginx 部署 Rails 应用
如何在 Ubuntu 14.04 上使用 Passenger 和 Nginx 部署 Rails 应用
23 0