环境准备
您必须将这些库
perl 5.6.1+
libreadline
libpcre
libssl
安装在您的电脑之中。 对于 Linux来说, 您需要确认使用 ldconfig 命令,让其在您的系统环境路径中能找到它们。
- CentOS 7 安装OpenResty所需依赖
[root@snails ~]# yum -y install readline-devel pcre-devel openssl-devel gcc
构建 OpenResty
下载
从下载页 Download下载最新的ngx_openresty源码包,并且像下面的示例一样将其解压:
[root@snails ~]# wget https://openresty.org/download/openresty-VERSION.tar.gz
[root@snails ~]# tar xzvf ngx_openresty-VERSION.tar.gz
VERSION 的地方替换成您下载的源码包的版本号,比如说 1.9.15.1。
编译安装
然后在进入 ngx_openresty-VERSION/
目录, 然后输入以下命令配置:
./configure --prefix=/root/openresty
默认, --prefix=/usr/local/openresty
程序会被安装到/usr/local/openresty目录。
您可以指定各种选项,比如
[root@snails openresty-1.9.15.1]# ./configure --prefix=/opt/openresty \
--with-luajit \
--with-http_stub_status_module
gmake
gmake install
试着使用 ./configure --help 查看更多的选项。
设置环境变量及文件软链接
[root@snails ~]# ln -s /usr/local/openresty/nginx /usr/local/nginx
[root@snails ~]# vi /etc/profile
export ORPATH=/usr/local/openresty
export PATH=$PATH:$ORPATH/bin:$ORPATH/nginx/sbin
配置用户及组
[root@snails nginx]# groupadd -f www
[root@snails nginx]# useradd -r -s /sbin/nologin -g www www
[root@snails nginx]# vi conf/nginx.conf
user www www;
验证
[root@snails nginx]# nginx
[root@snails nginx]# curl -I localhost
HTTP/1.1 200 OK
补充:
Nginx启动脚本/usr/lib/systemd/system/nginx.service
[root@snails nginx]# cat >> /usr/lib/systemd/system/nginx.service << EOF
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target
[Service]
Type=forking
PIDFile=/var/run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
[root@snails src]# systemctl status nginx
● nginx.service - nginx - high performance web server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: http://nginx.org/en/docs/
[root@snails src]# systemctl enable nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.
[root@snails src]# systemctl start nginx
[root@snails src]# systemctl reload nginx