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

Nginx 编译安装

作者头像
康怀帅
发布2018-02-28 15:05:31
8880
发布2018-02-28 15:05:31
举报
文章被收录于专栏:康怀帅的专栏康怀帅的专栏

本文介绍了手动编译安装 nginx 的具体步骤。

安装依赖包

RedHat 系

代码语言:javascript
复制
$ yum install -y gcc gcc-c++ pcre-devel openssl-devel zlib-devel

Debian 系

代码语言:javascript
复制
$ sudo apt install libpcre3 libpcre3-dev libssl-dev zlib1g-dev zlib1g

编译

代码语言:javascript
复制
$ ./configure --prefix=/etc/nginx  \
      --sbin-path=/etc/nginx/sbin/nginx \
      --conf-path=/etc/nginx/nginx.conf \
      --user=nginx \
      --group=nginx \
      --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-threads \
      --with-stream \
      --with-stream_ssl_module \
      --with-http_slice_module \
      --with-mail \
      --with-mail_ssl_module \
      --with-file-aio \
      --with-http_v2_module

错误排查

错误1

checking for OS Linux 3.10.0-327.36.1.el7.x86_64 x86_64 checking for C compiler … not found ./configure: error: C compiler cc is not found

代码语言:javascript
复制
$ yum install -y gcc gcc-c++

错误2

./configure: error: the HTTP rewrite module requires the PCRE library.You can either disable the module by using –without-http_rewrite_moduleoption, or install the PCRE library into the system, or build the PCRE librarystatically from the source with nginx by using –with-pcre=option.

代码语言:javascript
复制
$ yum install pcre-devel
$ sudo apt install libpcre3 libpcre3-dev

错误3

./configure: error: SSL modules require the OpenSSL library.You can either do not enable the modules, or install the OpenSSL libraryinto the system, or build the OpenSSL library statically from the sourcewith nginx by using –with-openssl=option.

代码语言:javascript
复制
$ yum install openssl-devel
$ sudo apt install libssl-dev

错误4

./configure: error: the HTTP gzip module requires the zlib library.

代码语言:javascript
复制
$ yum install zlib-devel
$ sudo apt install zlib1g-dev zlib1g

安装

代码语言:javascript
复制
$ make

$ groupadd -r nginx \
  && useradd -r -g nginx -s /bin/false -M nginx

$ sudo make install

加入环境变量

编辑 ~/.bash_profile

代码语言:javascript
复制
export PATH=/etc/nginx/sbin:$PATH

编辑 /etc/sudoers

注意:必须编辑此文件,否则 sudo 会找不到命令。

代码语言:javascript
复制
Defaults	secure_path="/etc/nginx/sbin:..."

systemd

/etc/systemd/system/ 下增加 nginx.service 文件,以下路径根据实际自己修改。

代码语言:javascript
复制
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/etc/nginx/run/nginx.pid
ExecStartPre=/etc/nginx/sbin/nginx -t -c /etc/nginx/nginx.conf
ExecStart=/etc/nginx/sbin/nginx -c /etc/nginx/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

启动

代码语言:javascript
复制
$ sudo nginx -t

$ sudo nginx

相关链接

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-09-15,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 安装依赖包
  • 编译
  • 错误排查
    • 错误1
      • 错误2
        • 错误3
          • 错误4
          • 安装
            • 加入环境变量
            • systemd
            • 启动
            • 相关链接
            领券
            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档