nginx编译安装
nginx
安装
1、编译安装
前提;需要编译环境,gcc、g++开发库之类
centos下
安装make
yum -y install gcc automake autoconf libtool make
安装g++
yum install gcc gcc-c++
ubuntu
apt-get install build-essential
apt-get install libtool
安装nginx
需要先安装pcre、zlib
pcre:为了重写rewrite
zlib:为了gzip压缩
1、选定源码目录
cd /usr/local/src
2、安装PCRE库
cd /usr/local/src
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
tar -zxvf pcre-8.37.tar.gz
cd pcre-8.34
./configure
make
make install
3、安装zlib库
cd /usr/local/src
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -xzvf zlib-1.2.11.tar.gz
cd zlib-1.2.11
./configure
make
make install
4、安装ssl
cd /usr/local/src
wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz
tar -zxvf openssl-1.0.1t.tar.gz
5、安装nginx
一般有两个版本,开发版和稳定版
把nginx安装到/usr/local/nginx
cd /usr/local/src
wget http://nginx.org/download/nginx-1.4.2.tar.gz
tar -zxvf nginx-1.4.2.tar.gz
cd nginx-1.4.2
./configure --sbin-path=/usr/local/nginx/nginx \
--conf-path=/usr/local/nginx/nginx.conf \
--pid-path=/usr/local/nginx/nginx.pid \
--with-http_ssl_module \
--with-pcre=/usr/local/src/pcre-8.38 \
--with-zlib=/usr/local/src/zlib-1.2.11 \
--with-openssl=/usr/local/src/openssl-1.0.1t
make
make install
6、启动
a、确保系统的80端口没有被占用
netstat -ano | grep 80
b、/usr/local/nginx/nginx
c、查看页面
访问localhost或者本机IP
#####################################################
安装nginx时,make 报错:
src/core/ngx_murmurhash.c: 在函数‘ngx_murmur_hash2’中:
src/core/ngx_murmurhash.c:37:11: 错误:this statement may fall through [-Werror=implicit-fallthrough=]
37 | h ^= data[2] << 16;
| ~~^~~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:38:5: 附注:here
38 | case 2:
| ^~~~
src/core/ngx_murmurhash.c:39:11: 错误:this statement may fall through [-Werror=implicit-fallthrough=]
39 | h ^= data[1] << 8;
| ~~^~~~~~~~~~~~~~~
src/core/ngx_murmurhash.c:40:5: 附注:here
40 | case 1:
| ^~~~
cc1:所有的警告都被当作是错误
make[1]: *** [objs/Makefile:447:objs/src/core/ngx_murmurhash.o] 错误 1
make[1]: 离开目录“/usr/local/src/nginx-1.4.2”
make: *** [Makefile:8:build] 错误 2
原因,是将警告当成了错误处理,打开/usr/local/src/nginx-1.4.2/objs/Makefile,
去掉CFLAGS中的-Werror
再重新make
-Wall 表示打开gcc的所有警告
-Werror,它要求gcc将所有的警告当成错误进行处理