编译安装

下载源码:

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

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

1yum install -y gcc
2yum install -y pcre-devel
3yum install -y openssl openssl-devel

编译安装:

1./configure \
2    --with-http_ssl_module \
3    --with-http_realip_module \
4    --user=www \
5    --group=www
6make
7make install

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

创建nginx用户www:

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

启动与停止

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

 1[Unit]
 2Description=nginx
 3After=network.target
 4
 5[Service]
 6Type=forking
 7PIDFile=/usr/local/nginx/logs/nginx.pid
 8ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
 9ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
10ExecReload=/usr/local/nginx/sbin/nginx -s reload
11ExecStop=/bin/kill -s QUIT $MAINPID
12PrivateTmp=true
13
14[Install]
15WantedBy=multi-user.target
1systemctl enable nginx
2systemctl start nginx

参考