1、yum install pcre-devel Pcre是语言兼容正则表达式 此时安装是为了使nginx支持http rewrite 模块 2、tar zxvf nginx.tar.gz Tar 中 -z 支持.tar.gz --j 支持.tar.bz2 -v 显示过程 -C 解压路径 -f 文件名 -x 解压 3、cd nginx 4、Vi auto/cc/gcc #CFLAGS=”$CFLAGS -g” (注释掉这行,去掉debug 模式编译,编译以后程序只有几百k) 5、vi src/core/nginx.h #define NGINX_VERSION "1.0.2” #define NGINX_VER "nginx" (修改此行,去掉后面的“NGINX_VERSION”,为了安全,这样编译后外 界无法获取程序的版本号) 6./configure --user=mersap --group=mersap --prefix=/usr/local/nginx --with- http_stub_status_module --with-http_ssl_module 此时 会出现报错,无非就是依赖包 gcc openssl-devel zlib-devel pcre-devel 这4个软件库是必须有的 7、make 自己执行时报出错误: src/http/ngx_http_variables.c:1987: error: expected expression before 鈥?鈥?token src/http/ngx_http_variables.c:1991: error: expected expression before 鈥?鈥?token make[1]: *** [objs/src/http/ngx_http_variables.o] Error 1 make[1]: Leaving directory `/usr/local/src/nginx-1.2.7' make: *** [build] Error 2 查看文件src/http/ngx_http_variables.c 1987行和1991行 发现是NGINX_VERSION 的问题 查看 vi src/core/nginx.h #define NGINX_VERSION NGINX_VERSION后面没有任何值 修改 改为NGINX_VERSION “” 重新编译执行 通过 8、make install 此时nginx已经安装完成 ln -s /usr/local/nginx/sbin/nginx /usr/sbin 或者将nginx直接写入全局变量 Vim /etc/profile 最后一行中加入 export PATH=$PATH:/usr/local/nginx/sbin; 保存退出 执行source /etc/profile 使全局配置文件生效 执行 nginx 进行测试 http://localhost:
|