- 下载
wget http://nginx.org/download/nginx-1.14.0.tar.gz
- 解压
tar -zxvf nginx-1.14.0.tar.gz -C /usr/local
- 进入文件 进行编译
yum -y install gcc gcc-c++ autoconf automake make
cd /usr/local/nginx-1.14.0
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi
make
可能会报错:
cc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I /usr/download/nginx_upstream_check_module-master/ -I objs \
-o objs/src/os/unix/ngx_user.o \
src/os/unix/ngx_user.c
src/os/unix/ngx_user.c: 在函数‘ngx_libc_crypt’中:
src/os/unix/ngx_user.c:26:7: 错误:‘struct crypt_data’没有名为‘current_salt’的成员
cd.current_salt[0] = ~salt[0];
处理方案;
打开 src/os/unix/ngx_user.c
#ifdef __GLIBC__
/* work around the glibc bug */
cd.current_salt[0] = ~salt[0]; ##把这一行注释掉
#endif
- 编译安装
make install
可能会报错
igned int (*)(struct <匿名> *)’} to ‘void (*)(ngx_http_script_engine_t *)’ {或称 ‘void (*)(struct <匿名> *)’} [-Werror=cast-function-type]
code->code = (ngx_http_script_code_pt)
^
src/http/ngx_http_script.c: 在函数‘ngx_http_script_add_full_name_code’中:
src/http/ngx_http_script.c:1296:18: 错误:cast between incompatible function types from ‘size_t (*)(ngx_http_script_engine_t *)’ {或称 ‘long unsigned int (*)(struct <匿名> *)’} to ‘void (*)(ngx_http_script_engine_t *)’ {或称 ‘void (*)(struct <匿名> *)’} [-Werror=cast-function-type]
code->code = (ngx_http_script_code_pt) ngx_http_script_full_name_len_code;
^
cc1:所有的警告都被当作是错误
make[1]: *** [objs/Makefile:893:objs/src/http/ngx_http_script.o] 错误 1
make[1]: 离开目录“/usr/download/nginx-1.14.1”
make: *** [Makefile:8:build] 错误 2
解决办法:打开 vim objs/Makefile 把 -Werrori删掉
- 启动:
cd /usr/local/nginx
./sbin/nginx -s reload
可能报错:
nginx: [error] open() "/usr/local/nginx-1.14.1/logs/nginx.pid" failed (2: No such file or directory)
解决方案:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ps -A | grep nginx
查看nginx 是否启动
浏览器进行访问
ip+80
出现403
解决方案1
配置文件头
把配置文件头部的#user nginx;注释去掉改为 user root;