在CentOS上编译安装Nginx

2015-01-03 阅读: Nginx

编译安装

下载源码:

wget http://nginx.org/download/nginx-<version>.tar.gz
tar -zxvf nginx-1.10.3.tar.gz
cd nginx-<version>

准备构建环境compiler,OpenSSL,PCRE(Perl Compatible Regular Expressions):

yum install -y gcc
yum install -y pcre-devel
yum install -y openssl openssl-devel

编译安装:

./configure \
    --with-http_ssl_module \
    --with-http_realip_module \
    --user=www \
    --group=www
make
make install

默认按在/usr/local/nginx目录下,可以使用configure参数--prefix 定制安装目录, 其他configure参数参考这里。 执行sbin/nginx -V可以打印安装时的编译参数。

创建nginx用户www:

groupadd www
useradd -g www -d /var/lib/www -s /sbin/nologin www
chown -R www:www /usr/local/nginx

启动与停止

/usr/lib/systemd/system/nginx.service

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/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=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target
systemctl enable nginx
systemctl start nginx

参考

标题:在CentOS上编译安装Nginx
本文链接:https://blog.frognew.com/2015/01/install-nginx.html
转载请注明出处。

目录