您的位置:首页 > 运维架构 > Nginx

nginx安装

2015-07-23 00:15 573 查看
系统 ubuntu14.04 64位

如果你的物理机上用 apt-get 安装了老版的 nginx,或者你的 nginx 有问题,可以使用 apt-get purge nginx 命令删除已安装的 nginx

对于一般新手而言 sudo apt-get install nginx 就够了;如果你乐于折腾,需要定制,那就源码安装吧(这里只会简单叙述)。

1.安装模块需要的库

gzip 模块需要 zlib 库

rewrite 模块需要 pcre 库

ssl 功能需要 openssl 库

sudo apt-get install zlib1g-dev
sudo apt-get install libpcre3 libpcre3-dev libpcrecpp0
sudo apt-get install libssl-dev


2.http://nginx.org/en/download.html 选取一个版本的nginx的下载地址,利用wget工具下载源码包到本地.这里选取1.4.7.

wget http://nginx.org/download/nginx-1.4.7.tar.gz[/code] 
解压

tar zxvf nginx-1.4.7.tar.gz


3.安装前配置

–with-http_stub_status_module:支持nginx状态查询

–with-http_ssl_module:支持https

–with-http_spdy_module:支持google的spdy, spdy是Google开发的基于TCP的应用层协议,用以最小化网络延迟,提升网络速度

–with-pcre:为了支持rewrite重写功能,必须制定pcre

–prefix: 指定安装位置

进入nginx源码目录

cd nginx-1.4.7


执行如下命令

./configure --prefix=/usr/local/nginx-1.4.7 \
--with-http_ssl_module --with-http_spdy_module \
--with-http_stub_status_module --with-pcre


输出如下内容,表示配置成功



4.编译

若未安装make,请先安装make

sudo apt-get install make


编译

make
make install


5.启动、关闭、重启

启动

直接执行可执行文件即可

/usr/loca/nginx-1.4.7/sbin/nginx


停止

/usr/loca/nginx-1.4.7/sbin/nginx -s stop


重启

有时更改了配置文件时使用

/usr/loca/nginx-1.4.7/sbin/nginx -s reload


可以通过curl查看nginx是否成功安装并运行

curl http://localhost[/code] 
若成功,则输出如下信息

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: