ubuntu安装Nginx

本机:

nginx-1.7.7.tar.gz

pcre-8.34.tar.gz


1、模块依赖性
gzip 模块需要 zlib 库
rewrite 模块需要 pcre 库
ssl 功能需要 openssl 库
预先编译好的安装包
sudo apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev


2、nginx的准备工作
下载nginx-1.7.7.tar.gz包到你指定的目录下后,解压:
tar zxvf nginx-1.7.7.tar.gz
解压后在当前目录下会生成一个nginx-1.7.7的目录
进入解压后的目录,运行configure命令,
 ./configure 
这时会报出一个如下错误:
./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= option.
这是因为没有PCRE library的原因所致,通过下面的命令安装相关的lib即可解决


3、PCRE库的安装:
1)解压:
tar –zxvf pcre-8.34.tar.gz
解压目录为:pcre-8.34
然后进入到 cd pcre-8.34,进行配置、编译、安装
2)配置
./configure 
3)编译pcre
make
make pcre时会出错
libtool: compile: unrecognized option `-DHAVE_CONFIG_H'
libtool: compile: Try `libtool --help' for more information.
make[1]: *** [pcrecpp.lo] Error 1
make[1]: Leaving directory `/home/mfcai/pcre-8.10'
make: *** [all] Error 2
安装build-essential
apt-get install build-essential
4)安装pcre
make install


4、nginx的安装

./configure 
make
make install

 

Nginx会被安装在/usr/local/nginx目录下(也可以使用参数--prefix=指定自己需要的位置),
安装成功后 /usr/local/nginx 目录下有四个子目录分别是:conf、html、logs、sbin 。
其中 Nginx 的配置文件存放于 conf/nginx.conf,
bin文件是位于 sbin 目录下的 nginx 文件。
确保系统的 80 端口没被其他程序占用,运行 sbin/nginx 命令来启动 Nginx
打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功!!!


5、常用命令

#切换到
cd usr/local/nginx/sbin
(权限不够加sudo!!!)
#启动
./nginx
#重启
./nginx -s reload
#判断配置文件是否正确
./nginx -t
#关闭
./nginx -s stop
或者
查询nginx主进程号
ps -ef | grep nginx
从容停止   kill -QUIT 主进程号

快速停止   kill -TERM 主进程号

强制停止   kill -9 nginx

若nginx.conf配置了pid文件路径,如果没有,则在logs目录下

kill -信号类型 '/usr/local/nginx/logs/nginx.pid'


参考来自:

blog.sina.com.cn/s/blog_4ad7c2540101duql.html

www.cnblogs.com/jianxie/p/3990377.html


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值