前言
nginx在项目中的使用越来越广泛了,记录一下nginx安装过程及自启动配置。
准备工作
操作系统:CentOS 7.3 X64
nginx编译安装需要先安装编译环境gcc gcc-c++。
需要安装的软件包括:
pcre-8.40.tar.gz //为了rewrite
zlib-1.2.11.tar.gz //为了gzip压缩
openssl-1.0.2l.tar.gz //为了SSL
nginx-1.10.3.tar.gz
上述软件包默认已上传至/opt/download
安装
1、安装pcre
# cd /opt/download
# tar -zxvf pcre-8.40.tar.gz
# cd pcre-8.40
# ./configure
# make
# make check
# make install
2、安装zlib
# cd /opt/download
# tar -xvf zlib-1.2.11.tar.gz
# cd zlib-1.2.11
# ./configure
# make
# make check
# make install
3、安装openssl
# cd /opt/download
# tar -zxvf openssl-1.0.2l.tar.gz
# cd openssl-1.0.2l
# ./config
# make
# make install
4、安装nginx
nginx安装目录为:/usr/local/nginx
# mkdir /usr/local/nginx
# cd /opt/download
# tar -xvf nginx-1.10.3.tar.gz
# cd nginx-1.10.3
# ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre=/opt/download/pcre-8.40 --with-zlib=/opt/download/zlib-1.2.11 --with-openssl=/opt/download/openssl-1.0.2l
# make
# make install
其中编译选项:--with-pcre、--with-zlib、--with-openssl指向的是源码路径。
安装成功后,可以通过 /usr/local/nginx/sbin/nginx -V 查看编译时候的参数。
nginx参数
nginx启动命令:
# /usr/local/nginx/sbin/nginx
nginx重启命令:
# /usr/local/nginx/sbin/nginx -s reload
nginx停止命令:
# /usr/local/nginx/sbin/nginx -s stop
配置开机自启动
采用编写shell脚本方式配置开机自启动。
# vi /etc/init.d/nginx
输入如下内容:
开机启动脚本
# chmod a+x /etc/init.d/nginx
将此命令加入到rc.local文件中,这样开机的时候nginx就默认启动了
# vi /etc/rc.local
加入一行 /etc/init.d/nginx start 保存并退出,下次重启会生效
nginx在项目中的使用越来越广泛了,记录一下nginx安装过程及自启动配置。
结语
本文只是记录了nginx的一种安装方式及开机自启动配置。未来还有nginx.conf的配置和nginx日志分割及日志分析等分享。
本文暂时没有评论,来添加一个吧(●'◡'●)