ubuntu 源码安装 nginx

本文介绍如何从源码编译安装 Nginx 1.8.0 版本,并详细列出所需的依赖库及模块配置。涵盖了安装依赖库、下载源码、编译配置等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.安装所需库

sudo apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev 

2.下载源码并解压缩
http://nginx.org/download/
3.编译安装

./configure --prefix=/usr/local/nginx-1.8.0 \
--with-http_ssl_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_spdy_module \
--with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' \
--with-debug

编译结果..设定的目录为:

  nginx path prefix: "/usr/local/nginx-1.8.0"
  nginx binary file: "/usr/local/nginx-1.8.0/sbin/nginx"
  nginx configuration prefix: "/usr/local/nginx-1.8.0/conf"
  nginx configuration file: "/usr/local/nginx-1.8.0/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx-1.8.0/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx-1.8.0/logs/error.log"
  nginx http access log file: "/usr/local/nginx-1.8.0/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"

sudo make && sudo make install
Ubuntu源码安装Nginx 1.20通常涉及以下几个步骤: 1. **下载Nginx源码**: 首先,你需要从Nginx官方网站下载最新版本的源码包。访问 http://nginx.org/en/download.html ,找到适用于Ubuntu的tar.gz文件,例如 `nginx-1.20.1.tar.gz`。 2. **创建安装目录**: 使用`sudo`权限创建一个用于安装的目录,如 `/usr/local/nginx`: ```bash sudo mkdir -p /usr/local/nginx ``` 3. **解压并进入目录**: ```bash sudo tar zxf nginx-1.20.1.tar.gz -C /usr/local/nginx --strip-components=1 cd /usr/local/nginx ``` 4. **配置环境变量和路径**: 编辑环境变量,将Nginx添加到PATH中,通常在 `~/.bashrc` 或 `~/.bash_profile` 中追加: ```bash export PATH=$PATH:/usr/local/nginx/sbin ``` 5. **配置SSL支持(可选)**: 如果需要HTTPS功能,可以安装OpenSSL,然后配置SSL证书: ```bash sudo apt-get update sudo apt-get install openssl ``` 6. **编译安装**: 进入配置阶段,运行 `configure` 命令: ```bash ./configure --prefix=/usr/local/nginx --with-http_ssl_module ``` 完成配置后,进行编译和安装: ```bash make && sudo make install ``` 7. **启动、测试和服务管理**: - 启动Nginx: ```bash sudo systemctl start nginx ``` - 检查是否成功启动: ```bash sudo systemctl status nginx ``` - 可以设置开机自启: ```bash sudo systemctl enable nginx ``` 8. **配置站点**: Nginx的主配置文件通常是 `/etc/nginx/nginx.conf`,在此基础上添加或修改虚拟主机配置,然后重启服务使其生效。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值