浏览器到 http://nginx.org/en/download.html
下载 stable version的nginx 如nginx-1.10.1.tar.gz,这是一个nginx源码包,需要经过编译和安装才能使用。
解压命令: tar –zxvf nginx-1.10.1.tar.gz
cd nginx解压目录 : ./configure 命令
问题一:gcc和gcc++ 编译器未安装
./configure: error: C compiler cc is not found
解决:安装gc++
sudo apt-get install gcc
sudo apt-get install gcc++
问题二: http模块缺少prce正则表达式库
./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库
sudo apt-get install libpcre3 libpcre3-dev
问题三: http gzip 模块缺少 zlib库
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.
解决:安装zlib库
$ sudo apt-get install zlib1g
$ sudo apt-get install zlib1g.dev
再次:./configure
编译 make
安装 make install
进入nginx安装目录
cd /usr/local/
ls 可以看到nginx,则代表nginx在ubuntu上安装成功了
进入 cd /usr/local/nginx/sbin
sudo ./nginx 启动nginx
若nginx没有启动成功,很可能是80端口被占用了,更换一下端口即可(编辑conf/nginx.conf文件 80改为81)