1.下载
nginx下载的地址:https://nginx.org/en/download.html
我选择的版本:1.10.3
2.解压
指定一个目录下面放置下载的文件,然后解压文件
命令:tar zxvf nginx-1.6.3.tar.gz
3.安装
然后进入到解压的目录下:
执行命令:
3.1 执行命令1:
./configure
注意可能遇到报错:
错误1:
/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=<path> option.
解决1:
sudo apt-get install libpcre3 libpcre3-dev
3.2 执行命令2:
make
可能遇到错误1:
src/core/ngx_murmurhash.c:37:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
h ^= data[2] << 16;
~~^~~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:38:5: note: here
case 2:
^~~~
src/core/ngx_murmurhash.c:39:11: error: this statement may fall through [-Werror=implicit-fallthrough=]
h ^= data[1] << 8;
~~^~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:40:5: note: here
原因:将警告当成错误处理
解决错误1:进入到nginx-1.6.3目录下(解压的目录)
找到当前目录下找到objs文件夹,并进入,打开文件Makefile,找到有一下内容的这行:
CFLAGS = -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g
把这行内容中的 “-Werror”去掉
-Werror: gcc将所有的警告当成错误进行处理
转至博客:https://segmentfault.com/a/1190000016370803
3.3 执行命令3:
sudo make install
4.启动,重启,停止
nginx默认安装到:
/usr/local/nginx
进入到该目录下(注意:一定要进入到该目录下面,不然下面的命令无效):
cd /usr/local/nginx
启动:
sudo sbin/nginx
查看是否成功
ps aux | grep nginx
重新加载配置文件
sudo sbin/nginx -s reload
停止nginx服务:
sudo sbin/nginx -s stop
5.卸载nginx
sudo apt-get --purge autoremove nginx
6.查看nginx版本
注意:一定要进入nginx安装目录下
sbin/nginx -V