0%

Linux下 编译安装Nginx 1.4.1

环境是ubuntu12.04 server,安装nginx 1.4.1和ngx_cache_purge模块,ngx_cache_purge功能是当nginx作为反向代理时,可以删除指定url的缓存,如果nginx作http服务器,可以不装. 先装PCRE library,nginx依赖这个库,下载:http://sourceforge.net/projects/pcre/files/pcre/,当前最新版8.32 unzip pcre-8.32.zip cd pcre-8.32 ./configure make make install 创建www用户组和www用户,并创建/home/www目录 groupadd www useradd -g www -s /sbin/nologin -M www mkdir /home/www chown -R www:www /home/www 下载好 nginx-1.4.1.tar.gz,ngx_cache_purge-2.1.tar.gz tar zxvf nginx-1.4.1.tar.gz tar zxvf ngx_cache_purge-2.1.tar.gz cd nginx-1.4.1 ./configure --user=www --group=www --add-module=../ngx_cache_purge-2.1 --prefix=/home/server/nginx-1.4.1 --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_gzip_static_module --with-http_random_index_module --with-http_sub_module --with-http_dav_module make make install prefix参数是nginx的安装位置,with-http_stub_status_module是打开status模块(查看nginx当前状态) http_realip_module 作为代理服务器时,服务端可获取到用户真实的IP http_addition_module 可在响应前后添加一个过滤器 http_gzip_static_module 预压缩文件传前检查,防止文件被重复压缩 http_random_index_module 随机主页 如果在指定的location中指定,将为每一个请求扫描指定目录中的文件,并且随机选择一个代替index.html,但是不会选择以“.”开头的文件。 http_sub_module 反向代理时替换URL http_dav_module 开启WebDAV扩展动作模块,可为文件和目录指定权限 以上模块根据自己需要添加,官方模块列表:http://wiki.nginx.org/Modules 修改nginx.conf配置: vi /home/server/nginx-1.4.1/conf/nginx.conf 头部添加 user www www; 使用www组的www用户启动nginx 找到server location,修改www根目录 location / { root /home/www; index index.html index.htm; } 启动nginx: /home/server/nginx-1.4.1/sbin/nginx 这个时候,一般会报错,提示: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory 建立链接: 32位系统: ln -s /usr/local/lib/libpcre.so.1 /lib 64位系统: ln -s /usr/local/lib/libpcre.so.1 /lib64