编译安装
下载源码:
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.targetsystemctl enable nginx
systemctl start nginx