Ubuntu 编译安装nginx

2,665 阅读1分钟

环境

Ubuntu 18.04.2 LTS

下载源码

# 官网下载地址 http://nginx.org/en/download.html
wget http://nginx.org/download/nginx-1.17.9.tar.gz

解压源码

tar xvf nginx-1.16.1.tar.gz

查看config参数, 里面是一些我们可以添加编译的模块

cd nginx-1.17.9/
./configure --help | less

常见模块
--with-http_ssl_module
--without-http_gzip_module
--without-http_proxy_module

编译

  1. 生成Makefile
--prefix:  用于指定安装目录
./configure --prefix=/home/dong/code/nginx

# 如果需要gzip可以这样写
./configure --prefix=/home/dong/code/nginx --without-http_gzip_module
  1. 编译
make
  1. 安装
make install
  1. 验证目录
# 查看安装目录
ls /home/dong/code/nginx
conf  html  logs  sbin
# nginx 在sbin目录下面

查看nginx版本

./nginx -V
nginx version: nginx/1.17.9
built by gcc 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
configure arguments: --prefix=/home/dong/code/nginx

访问

  1. 启动nginx
# 默认使用80端口,需要管理员权限启动
./nginx
  1. 访问
# 浏览器中访问
http://localhost/