1、下载
到 Nginx 官方 下载安装包,当前版本是 1.5.13 版本
$ wget http://nginx.org/download/nginx-1.5.13.tar.gz
$ tar -xvzf nginx-1.5.13.tar.gz
2、检查、编译、安装
$ ./configure #检查编译前置条件
$ make #编译
$ sudo make install #使用sudo权限进行安装
3、安装路径
安装后路径在 /usr/local/
$ pwd
/usr/local/nginx
john@ubuntu:nginx$ ll
总用量 16
drwxr-xr-x 2 root root 4096 4月 16 20:30 conf/
drwxr-xr-x 2 root root 4096 4月 16 20:30 html/
drwxr-xr-x 2 root root 4096 4月 16 20:30 logs/
drwxr-xr-x 2 root root 4096 4月 16 20:30 sbin/
4、测试
$ sudo ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
5、启动
$ sudo sbin/nginx
6、验证
Nginx 默认端口为 80 ,直接打开浏览器,输入 http://localhost 即可看到结果。
7、配置服务
Nginx 安装后是没有向系统服务中注册,需要手工注册。
1)使用在 /etc/init.d/ 目录下创建名为 nginx 文件,注意没有后缀名,将以下内容复制到该文件中(感谢提供脚本的兄弟)。
#! /bin/sh
#用来将Nginx注册为系统服务的脚本
#Author CplusHua
#http://www.219.me
#chkconfig: - 85 15
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="Nginx Daemon"
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
SCRIPTNAME=/etc/init.d/$NAME
#守护进程不存在就退出
test -x $DAEMON ||exit 0
d_start(){
$DAEMON ||echo -n "aready running"
}
d_stop(){
$DAEMON -s quit || echo -n "not running"
}
d_reload(){
$DAEMON -s reload || echo -n "could not reload"
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
reload)
echo -n "Reloading $DESC: configurationg....."
d_reload
echo "reloaded."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 3
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
;;
esac
exit 0
2)添加权限
$ sudo chmod +x nginx
3)服务方式启动
如果配置服务前已启动,执行以下命令停止Nginx。
$ sudo service nginx stop
启动Nginx
$ sudo service nginx start
转载请标明出处:http://blog.csdn.net/johnnycode/article/details/23871339
参考文章: