Ubuntu nginx 压缩包方式安装 && 使用包管理工具安装

压缩包方式安装

我打算把nginx安装到/opt/nginx/目录中,以下操作用普通用户wuyujin执行。

wget http://nginx.org/download/nginx-1.16.1.tar.gz  # 下载源码包,其他版本见<http://nginx.org/en/download.html>。

sudo mkdir /opt/nginx               # 新建nginx安装目录
sudo chown wuyujin -R /opt/nginx/   # 修改目录属主

tar -zxf nginx-1.16.1.tar.gz        # 解压源码包
cd nginx-1.16.1/                    # 进入源码文件夹

./configure --prefix=/opt/nginx     # 配置
make            # 编译
make install    # 安装

ll /opt/nginx/  # 查看目录结构
tree /opt/nginx -L 2

操作过程如下:

wuyujin@ubuntu18:~/Downloads$ sudo mkdir /opt/nginx               # 新建nginx安装目录
wuyujin@ubuntu18:~/Downloads$ sudo chown wuyujin -R /opt/nginx/   # 修改目录属主
wuyujin@ubuntu18:~/Downloads$ tar -zxf nginx-1.16.1.tar.gz        # 解压源码包
wuyujin@ubuntu18:~/Downloads$ cd nginx-1.16.1/                    # 进入源码文件夹
wuyujin@ubuntu18:~/Downloads/nginx-1.16.1$ ./configure --prefix=/opt/nginx     # 配置
checking for OS
 + Linux 5.3.0-40-generic x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) 
checking for gcc -pipe switch ... found
///// ... 省略多行信息
creating objs/Makefile

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + using system zlib library

  nginx path prefix: "/opt/nginx"
  nginx binary file: "/opt/nginx/sbin/nginx"
  nginx modules path: "/opt/nginx/modules"
  nginx configuration prefix: "/opt/nginx/conf"
  nginx configuration file: "/opt/nginx/conf/nginx.conf"
  nginx pid file: "/opt/nginx/logs/nginx.pid"
  nginx error log file: "/opt/nginx/logs/error.log"
  nginx http access log file: "/opt/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

wuyujin@ubuntu18:~/Downloads/nginx-1.16.1$ make            # 编译
make -f objs/Makefile
make[1]: Entering directory '/home/wuyujin/Downloads/nginx-1.16.1'
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/src/core/nginx.o \
	src/core/nginx.c
///// ... 省略多行信息
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
	-o objs/ngx_modules.o \
	objs/ngx_modules.c
cc -o objs/nginx \
objs/src/core/nginx.o \
///// ...省略多行信息
objs/src/http/modules/ngx_http_upstream_zone_module.o \
objs/ngx_modules.o \
-ldl -lpthread -lcrypt -lpcre -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/opt/nginx|" \
	-e "s|%%PID_PATH%%|/opt/nginx/logs/nginx.pid|" \
	-e "s|%%CONF_PATH%%|/opt/nginx/conf/nginx.conf|" \
	-e "s|%%ERROR_LOG_PATH%%|/opt/nginx/logs/error.log|" \
	< man/nginx.8 > objs/nginx.8
make[1]: Leaving directory '/home/wuyujin/Downloads/nginx-1.16.1'
wuyujin@ubuntu18:~/Downloads/nginx-1.16.1$ make install    # 安装
make -f objs/Makefile install
make[1]: Entering directory '/home/wuyujin/Downloads/nginx-1.16.1'
test -d '/opt/nginx' || mkdir -p '/opt/nginx'
test -d '/opt/nginx/sbin' \
	|| mkdir -p '/opt/nginx/sbin'
test ! -f '/opt/nginx/sbin/nginx' \
	|| mv '/opt/nginx/sbin/nginx' \
		'/opt/nginx/sbin/nginx.old'
cp objs/nginx '/opt/nginx/sbin/nginx'
test -d '/opt/nginx/conf' \
	|| mkdir -p '/opt/nginx/conf'
cp conf/koi-win '/opt/nginx/conf'
cp conf/koi-utf '/opt/nginx/conf'
cp conf/win-utf '/opt/nginx/conf'
test -f '/opt/nginx/conf/mime.types' \
	|| cp conf/mime.types '/opt/nginx/conf'
cp conf/mime.types '/opt/nginx/conf/mime.types.default'
test -f '/opt/nginx/conf/fastcgi_params' \
	|| cp conf/fastcgi_params '/opt/nginx/conf'
cp conf/fastcgi_params \
	'/opt/nginx/conf/fastcgi_params.default'
test -f '/opt/nginx/conf/fastcgi.conf' \
	|| cp conf/fastcgi.conf '/opt/nginx/conf'
cp conf/fastcgi.conf '/opt/nginx/conf/fastcgi.conf.default'
test -f '/opt/nginx/conf/uwsgi_params' \
	|| cp conf/uwsgi_params '/opt/nginx/conf'
cp conf/uwsgi_params \
	'/opt/nginx/conf/uwsgi_params.default'
test -f '/opt/nginx/conf/scgi_params' \
	|| cp conf/scgi_params '/opt/nginx/conf'
cp conf/scgi_params \
	'/opt/nginx/conf/scgi_params.default'
test -f '/opt/nginx/conf/nginx.conf' \
	|| cp conf/nginx.conf '/opt/nginx/conf/nginx.conf'
cp conf/nginx.conf '/opt/nginx/conf/nginx.conf.default'
test -d '/opt/nginx/logs' \
	|| mkdir -p '/opt/nginx/logs'
test -d '/opt/nginx/logs' \
	|| mkdir -p '/opt/nginx/logs'
test -d '/opt/nginx/html' \
	|| cp -R html '/opt/nginx'
test -d '/opt/nginx/logs' \
	|| mkdir -p '/opt/nginx/logs'
make[1]: Leaving directory '/home/wuyujin/Downloads/nginx-1.16.1'
wuyujin@ubuntu18:~/Downloads/nginx-1.16.1$ ll /opt/nginx/  # 查看目录结构
total 24
drwxr-xr-x  6 wuyujin root    4096 2月   9 23:48 ./
drwxr-xr-x 17 root    root    4096 2月   9 23:47 ../
drwxr-xr-x  2 wuyujin wuyujin 4096 2月   9 23:48 conf/
drwxr-xr-x  2 wuyujin wuyujin 4096 2月   9 23:48 html/
drwxr-xr-x  2 wuyujin wuyujin 4096 2月   9 23:48 logs/
drwxr-xr-x  2 wuyujin wuyujin 4096 2月   9 23:48 sbin/
wuyujin@ubuntu18:~/Downloads/nginx-1.16.1$ tree /opt/nginx -L 2
/opt/nginx
├── conf
│   ├── fastcgi.conf
│   ├── fastcgi.conf.default
│   ├── fastcgi_params
│   ├── fastcgi_params.default
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types
│   ├── mime.types.default
│   ├── nginx.conf
│   ├── nginx.conf.default
│   ├── scgi_params
│   ├── scgi_params.default
│   ├── uwsgi_params
│   ├── uwsgi_params.default
│   └── win-utf
├── html
│   ├── 50x.html
│   └── index.html
├── logs
└── sbin
    └── nginx

4 directories, 18 files
wuyujin@ubuntu18:~/Downloads/nginx-1.16.1$ 
  • 配置环境变量
    编辑/etc/profile,添加如下配置:
# nginx
export NGINX_HOME=/opt/nginx
export PATH=$NGINX_HOME/sbin:$PATH

重启使最新配置对所有用户生效。

  • 测试
    echo $NGINX_HOME
    nginx -v

包管理工具安装

wuyujin@ubuntu18:~$ apt-cache search nginx | grep ^nginx
nginx - small, powerful, scalable web/proxy server
nginx-common - small, powerful, scalable web/proxy server - common files
nginx-core - nginx web/proxy server (standard version)
nginx-doc - small, powerful, scalable web/proxy server - documentation
nginx-extras - nginx web/proxy server (extended version)
nginx-full - nginx web/proxy server (standard version)
nginx-light - nginx web/proxy server (basic version)
wuyujin@ubuntu18:~$ 

依赖问题

如果安装出现问题,如缺少依赖等,执行以下:

  • 安装依赖 sudo apt-get install gcc g++ autoconf automake make pcre pcre-devel openssl openssl-devel

其中,PCRE依赖如果不能通过包管理工具直接安装,使用以下操作,下载源码包编译安装:

wget https://ftp.pcre.org/pub/pcre/pcre-8.00.tar.gz # 更多版本见<http://www.pcre.org/>
tar -zxvf pcre-8.40.tar.gz 
cd pcre-8.00/
./configure
make
make install
whatis pcre  # Perl-compatible regular expressions
发布了269 篇原创文章 · 获赞 156 · 访问量 29万+

猜你喜欢

转载自blog.csdn.net/wuyujin1997/article/details/104242700
今日推荐