Linux下安装nginx

linux下安装nginx

————————————————————————
系统环境:
Linux下安装nginx
第一步:从http://nginx.org/en/download.html上下载相应的版本,这里下载的是当前的稳定版本nginx-1.12.2.tar.gz。
第二步:解压 tar -xzvf nginx-1.12.2.tar.gz
第三步:设置一下配置信息./configure –prefix=/usr/local/nginx(配置安装目录),或者不执行此步,直接默认配置
如果该步骤出现错误

/configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using –without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using –with-pcre= option.

可以使用以下命令

wget https://nchc.dl.sourceforge.net/project/pcre/pcre/8.41/pcre-8.41.tar.gz
wget https://nchc.dl.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz
wget https://www.openssl.org/source/openssl-1.0.2m.tar.gz

下载源代码文件,然后解压
tar -xzvf pcre-8.41.tar.gz
tar -xzvf zlib-1.2.11.tar.gz
tar -xzvf openssl-1.0.2m.tar.gz
之后执行配置命令

./configure –prefix=/usr/local/nginx –with-pcre=pcre-8.41 –with-zlib=zlib-1.2.11 –with-http_ssl_module –with-openssl=openssl-1.0.2m

第四步:make编译(make的过程是把各种语言写的源码文件,变成可执行文件和各种库文件),make install安装(make install把这些编译出来的可执行文件和库文件复制到合适的地方)。安装完成
Linux下安装nginx

启动nginx
使用命令/usr/local/nginx/sbin/nginx启动nginx
关闭nginx
使用ps -ef|grep nginx命令查看nginx的主进程号,这里是16776
Linux下安装nginx
从容停止Nginx:
kill -QUIT 主进程号
快速停止Nginx:
kill -TERM 主进程号
强制停止Nginx:
pkill -9 nginx

conf配置文件:当我们使用nginx进行配置时,需要对conf/nginx.conf文件进行修改,这个文件如果是只读的,那么我们需要先修改它的权限,使用命令chmod -R a+w conf/nginx.conf