前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Ubuntu 17.04 编译安装 Nginx 1.9.9

Ubuntu 17.04 编译安装 Nginx 1.9.9

作者头像
程序员鹏磊
发布2018-02-09 15:06:15
7970
发布2018-02-09 15:06:15
举报
文章被收录于专栏:架构师专栏架构师专栏

Ubuntu 17.04 编译安装 Nginx 1.9.9

安装

安装依赖

代码语言:javascript
复制
$ apt-get update
$ apt-get install build-essential libtool libpcre3 libpcre3-dev zlib1g-dev openssl openssl-devel

下载并解压

代码语言:javascript
复制
$ cd /opt/
$ wget http://nginx.org/download/nginx-1.9.9.tar.gz
$ tar zxvf nginx-1.9.9.tar.gz

编译

编译时候可以指定编译参数,参考文章尾部:常用编译选项

代码语言:javascript
复制
$ cd nginx-1.9.9
$ ./configure --prefix=/usr/local/nginx 

安装

代码语言:javascript
复制
$ make
$ make && make install

默认安装在/usr/local/nginx

里面有四个目录:

  • conf: 配置文件夹,最重要文件是nginx.conf
  • html: 静态网页文件夹
  • logs: 日志文件夹
  • sbin: nginx 的可执行文件,启动、停止等操作

常用命令

正确性检查

每次修改nginx配置文件后都要进行检查

代码语言:javascript
复制
$ /usr/local/nginx/sbin/nginx -t
代码语言:javascript
复制
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启动

代码语言:javascript
复制
$ /usr/local/nginx/sbin/nginx

浏览器输入本机IP ,看到如下内容证明安装成功

代码语言:javascript
复制
Welcome to nginx!

If you see this page, the nginx web server is successfully installed and working. Further configuration is required.

For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.

Thank you for using nginx.

停止

代码语言:javascript
复制
$ /usr/local/nginx/sbin/nginx -s stop

重启

代码语言:javascript
复制
$ /usr/local/nginx/sbin/nginx -s reload

常用编译选项

代码语言:javascript
复制
./configure \
--prefix=/home/nginx \
--sbin-path=/usr/sbin/nginx \
--user=nginx \
--group=nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/home/log/nginx/error.log \
--http-log-path=/home/log/nginx/access.log \
--with-http_ssl_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-http_realip_module \
--pid-path=/home/run/nginx.pid \
--with-pcre=/home/software/pcre-8.35 \
--with-zlib=/home/software/zlib-1.2.8 \
--with-openssl=/home/software/openssl-1.0.1i

选项说明

代码语言:javascript
复制
--prefix=/home/nginx \ Nginx安装的根路径,所有其它路径都要依赖该选项
--sbin-path=/usr/sbin/nginx \ nginx的可执行文件的路径(nginx)
--user=nginx \ worker进程运行的用户
--group=nginx \ worker进程运行的组
--conf-path=/etc/nginx/nginx.conf \  指向配置文件(nginx.conf)
--error-log-path=/var/log/nginx/error.log \ 指向错误日志目录
--http-log-path=/var/log/nginx/access.log \  设置主请求的HTTP服务器的日志文件的名称
--with-http_ssl_module \  使用https协议模块。默认情况下,该模块没有被构建。前提是openssl与openssl-devel已安装
--with-http_gzip_static_module \  启用ngx_http_gzip_static_module支持(在线实时压缩输出数据流)
--with-http_stub_status_module \  启用ngx_http_stub_status_module支持(获取nginx自上次启动以来的工作状态)
--with-http_realip_module \  启用ngx_http_realip_module支持(这个模块允许从请求标头更改客户端的IP地址值,默认为关)
--pid-path=/var/run/nginx.pid \  指向pid文件(nginx.pid)

设置PCRE库的源码路径,如果已通过yum方式安装,使用–with-pcre自动找到库文件。使用–with-pcre=PATH时,需要从PCRE网站下载pcre库的源码(版本4.4 – 8.30)并解压,剩下的就交给Nginx的./configure和make来完成。perl正则表达式使用在location指令和 ngx_http_rewrite_module模块中。
--with-pcre=/home/software/pcre-8.35 \ 

指定 zlib(版本1.1.3 – 1.2.5)的源码解压目录。在默认就启用的网络传输压缩模块ngx_http_gzip_module时需要使用zlib 。
--with-zlib=/home/software/zlib-1.2.8 \

指向openssl安装目录
--with-openssl=/home/software/openssl-1.0.1i

Contact

  • 作者:鹏磊
  • 出处:http://www.ymq.io
  • Email:admin@souyunku.com
  • 版权归作者所有,转载请注明出处
  • Wechat:关注公众号,搜云库,专注于开发技术的研究与知识分享
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017/08/18,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Ubuntu 17.04 编译安装 Nginx 1.9.9
    • 安装
      • 安装依赖
      • 下载并解压
      • 编译
      • 安装
    • 常用命令
      • 正确性检查
      • 启动
      • 停止
      • 重启
    • 常用编译选项
      • 选项说明
      • Contact
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档