menu Chancel's blog
rss_feed
Chancel's blog
我就是这样的人

Nginx的编译安装(安装自定义模块)

作者:Chancel, 更新:2018 Dec 28, 字数:1767, 已阅:673

这篇文章更新于 1620 天前,文中部分信息可能失效,请自行甄别无效内容。

准备

  • 安装必要的依赖
yum install -y gcc gcc-c++
yum install -y pcre pcre-devel openssl openssl-devel zlib zlib-devel
  • 创建运行nginx的用户(如果想以root用户运行nginx,则需要更改后续的编译配置)
useradd -s /sbin/nologin -M nginx
# 查看nginx的身份
id nginx
  • 下载并解压自定义模块(此处举例NCHAN)
https://github.com/slact/nchan/archive/v1.1.14.tar.gz
tar -zxvf v1.1.14.tar.gz

下载并解压nginx

wget https://github.com/nginx/nginx/archive/release-1.13.5.tar.gz
tar -zxvf release-1.13.5.tar.gz

编译并添加第三方模块

  • 编译配置
    • 以root用户运行:更改user和group为root
    • 自定义模块路径:add-module
    • 配置文件路径:prefix
    • 安装路径:sbin-path
. auto/configure \
--user=root                         \
--group=root                         \
--prefix=/etc/nginx                   \
--sbin-path=/usr/sbin/nginx           \
--conf-path=/etc/nginx/nginx.conf     \
--pid-path=/var/run/nginx.pid         \
--lock-path=/var/run/nginx.lock       \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module        \
--with-http_stub_status_module        \
--with-http_ssl_module                \
--with-pcre                           \
--with-file-aio                       \
--with-http_realip_module             \
--without-http_scgi_module            \
--without-http_uwsgi_module           \
--without-http_fastcgi_module         \
--add-module=/home/nginx/nchan-1.1.14
  • 编译并安装
make && make install

Nginx配置文件修改

  • 此处配置第三方模块Nchan,如无需配置可跳过
http {  
  server {
    listen       80;

    location = /sub {
      nchan_subscriber;
      nchan_channel_id foobar;
    }

    location = /pub {
      nchan_publisher;
      nchan_channel_id foobar;
    }
  }
}

运行Nginx

# cent7 OS 需要关闭防火墙
systemctl stop firewalld
nginx -c /etc/nginx/nginx.conf

[[replyMessage== null?"发表评论":"发表评论 @ " + replyMessage.m_author]]

account_circle
email
web_asset
textsms

评论列表([[messageResponse.total]])

还没有可以显示的留言...
[[messageItem.m_author]] [[messageItem.m_author]]
[[messageItem.create_time]]
[[getEnviron(messageItem.m_environ)]]
[[subMessage.m_author]] [[subMessage.m_author]] @ [[subMessage.parent_message.m_author]] [[subMessage.parent_message.m_author]]
[[subMessage.create_time]]
[[getEnviron(messageItem.m_environ)]]
目录