由于nginx在编译时默认的 http rewrite(使用正则表达式对请求进行重写) 模块依赖
PCRE(Perl Compatible Regular Expressions)库,官网:
http://www.pcre.org,所以需要先安装PCRE
如果未安装,编译时会提示如下:
./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.
安装PCRE:
cd ~/Downloads
tar xvzf pcre-8.38.tar
cd pcre-8.38
./configure --prefix=/usr/local
sudo make
sudo make install
安装Nginx:
如果想在编译时启用或禁用相关模块可以使用 --with-<module-name>-module和--without-<module-name>-module
此处完全采用默认配置。
cd ~/Downloads
tar xvzf nginx-1.10.1.tar
./configure --prefix=~/develop/nginx
sudo make
sudo make install
启动Nginx:
sudo nginx
在浏览器中输入:http://localhost 即可访问nginx欢迎页面。如果不行则安装或启动失败。
关闭nginx:
sudo nginx -s stop