Ubuntu下安装nginx的步骤分享
发布时间:2012-10-29 23:27:33 作者:佚名 我要评论
在Ubuntu下安装nginx的步骤介绍,使用Ubuntu的朋友可以参考下
1)、下载
sudo wget http://nginx.org/download/nginx-1.2.2.tar.gz
2)、解压
sudo tar -xzvf nginx-1.2.2.tar.gz
3)、进入相关目录进行以下操作
./configure
make
sudo make install
如果你运气好的话,一切ok,不过...........哈哈。Ubuntu默认的策略是什么库都不装,依赖的库都需要自已手工安装搞定。 一般都会出错的,那么我们来看看可能出现的问题。
4)、常见问题解决办法
缺少pcre library
./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-8.31解决问题,解压后对pcre进行如下操作
sudo wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gz
sudo tar -xzvf pcre-8.31.tar.gz
cd /usr/local/src/pcre-8.31
./configure
make
sudo make install
运气好一次通过,运气不好,make pcre时会出错
缺少gcc-c++和libtool,也就是c++编译包
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 `/usr/local/src//pcre-8.31'
make: *** [all] Error 2root@wolfdog-virtual-machine:~/work/pcre-8.12$ libtool -help -DHAVE_CONFIG_H
The program 'libtool' is currently not installed. You can install it by typing:
sudo apt-get install libtool
解决方法:需要先安装libtool和gcc-c++
?sudo apt-get install libtool
sudo apt-get install gcc-c++
大爷啊~~~这时候可能又会报错啊,坑爹啊~~~
缺少openssl库
./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.
缺少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.
解决办法:少什么就安装什么呗。
sudo apt-get install openssl libssl-dev libperl-dev
4)、解决了以上问题,编译nginx就没啥问题了。下面安装。(附加安装插件的方法)
先下载插件并解压
sudo wget https://github.com/agentzh/echo-nginx-module/tarball/v0.40rc1 -O echo-nginx-module.tar.gz
sudo wget https://nodeload.github.com/agentzh/memc-nginx-module/tarball/v0.13rc3 -O memc-nginx-module.tar.gz
sudo tar -xzvf echo-nginx-module.tar.gz
sudo tar -xzvf memc-nginx-module.tar.gz
进入nginx目录cd nginx-1.2.2/,执行以下命令
./configure --user=www-data --group=www-data --with-debug --with-http_gzip_static_module --with-http_ssl_module --with-pcre=../pcre-8.31/ --with-http_perl_module --with-perl=/usr/bin/perl --with-http_stub_status_module --with-http_realip_module \
--prefix=/usr/local/nginx \
--add-module=../agentzh-echo-nginx-module-9259898/ \
--add-module=../agentzh-memc-nginx-module-4007350/ \
注:前面一段是一些编译参数,后面add-module是添加模块
make -j2
make install
大爷的,又可能报错。没有nginx,logs目录访问权限
[alert]: could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)
2011/03/21 06:09:33 [emerg] 24855#0: mkdir() "/usr/local/nginx/client_body_temp" failed (13: Permission denied)
解决办法:
sudo chmod a+rwx -R logs
sudo chmod a+rwx -R /usr/local/nginx
现在,差不多没问题了。
可以进入/usr/local/nginx/sbin/执行以下命令看是否成功:
nginx -v
5)、nginx自启动
编辑启动脚本:
sudo vim /etc/init.d/nginx
#! /bin/bash
#
# nginx Start up the nginx server daemon
#
# chkconfig: 2345 55 25
# Description: starts and stops the nginx web server
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: starts and stops the nginx web server
### END INIT INFO
# To install:
# copy this file to /etc/init.d/nginx
# shell> chkconfig --add nginx (RedHat)
# shell> update-rc.d -f nginx defaults (debian)
# To uninstall:
# shell> chkconfig --del nginx (RedHat)
# shell> update-rc.d -f nginx remove
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/var/local/nginx/logs/$NAME.pid
ULIMIT=10240
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
echo "Starting $NAME ..."
ulimit -SHn $ULIMIT
$DAEMON -c $CONFIGFILE
}
do_stop() {
echo "Shutting down $NAME ..."
kill 'cat $PIDFILE'
}
do_reload() {
echo "Reloading $NAME ..."
kill -HUP 'cat $PIDFILE'
}
case "$1" in
start)
[ ! -f "$PIDFILE" ] && do_start || echo "nginx already running"
echo -e ".\ndone"
;;
stop)
[ -f "$PIDFILE" ] && do_stop || echo "nginx not running"
echo -e ".\ndone"
;;
restart)
[ -f "$PIDFILE" ] && do_stop || echo "nginx not running"
do_start
echo -e ".\ndone"
;;
reload)
[ -f "$PIDFILE" ] && do_reload || echo "nginx not running"
echo -e ".\ndone"
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload}" >&2
exit 1
;;
esac
exit 0
红色部分,根据自己的路径修改。
6)、常用命令
重启nginx:service nginx restart
启动:service nginx start
关闭:service nginx stop
7)、linux常用命令
tar(z-用 gzip 对存档压缩或解压;x-从存档展开文件;v-详细显示处理的文件;f-指定存档或设备)
tar –zxvf nginx-0.8.54.tar.gz
ip查看
ifconfig
编译
make
安装编译好的源码包
make install
编辑文件
sudo gedit /etc/profile
修改根限:chmod说明(u:与文件属主拥有一样的权限[a:所有人];+:增加权限;rwx:可读可写可执行)
-R:递归所有目录和文件
sudo chmod a+rwx -R logs
检查是库是否安装成功
dpkg --list|grep openssl
下载安装库
sudo apt-get install libtool
检查服务启动是否正常
ps -ef|grep
查找openssl安装路径
whereis openssl
更新源
sudo apt-get update
更新已安装的包
sudo apt-get upgrade
sudo wget http://nginx.org/download/nginx-1.2.2.tar.gz
2)、解压
sudo tar -xzvf nginx-1.2.2.tar.gz
3)、进入相关目录进行以下操作
复制代码
代码如下:./configure
make
sudo make install
如果你运气好的话,一切ok,不过...........哈哈。Ubuntu默认的策略是什么库都不装,依赖的库都需要自已手工安装搞定。 一般都会出错的,那么我们来看看可能出现的问题。
4)、常见问题解决办法
缺少pcre library
./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-8.31解决问题,解压后对pcre进行如下操作
复制代码
代码如下:sudo wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gz
sudo tar -xzvf pcre-8.31.tar.gz
cd /usr/local/src/pcre-8.31
./configure
make
sudo make install
运气好一次通过,运气不好,make pcre时会出错
缺少gcc-c++和libtool,也就是c++编译包
复制代码
代码如下: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 `/usr/local/src//pcre-8.31'
make: *** [all] Error 2root@wolfdog-virtual-machine:~/work/pcre-8.12$ libtool -help -DHAVE_CONFIG_H
The program 'libtool' is currently not installed. You can install it by typing:
sudo apt-get install libtool
解决方法:需要先安装libtool和gcc-c++
?sudo apt-get install libtool
sudo apt-get install gcc-c++
大爷啊~~~这时候可能又会报错啊,坑爹啊~~~
缺少openssl库
复制代码
代码如下:./configure: error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using
--without-http-cache option, or install the OpenSSL library into the system,
or build the OpenSSL library statically from the source with nginx by using
--with-http_ssl_module --with-openssl=<path> options.
缺少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.
解决办法:少什么就安装什么呗。
sudo apt-get install openssl libssl-dev libperl-dev
4)、解决了以上问题,编译nginx就没啥问题了。下面安装。(附加安装插件的方法)
先下载插件并解压
复制代码
代码如下:sudo wget https://github.com/agentzh/echo-nginx-module/tarball/v0.40rc1 -O echo-nginx-module.tar.gz
sudo wget https://nodeload.github.com/agentzh/memc-nginx-module/tarball/v0.13rc3 -O memc-nginx-module.tar.gz
sudo tar -xzvf echo-nginx-module.tar.gz
sudo tar -xzvf memc-nginx-module.tar.gz
进入nginx目录cd nginx-1.2.2/,执行以下命令
复制代码
代码如下:./configure --user=www-data --group=www-data --with-debug --with-http_gzip_static_module --with-http_ssl_module --with-pcre=../pcre-8.31/ --with-http_perl_module --with-perl=/usr/bin/perl --with-http_stub_status_module --with-http_realip_module \
--prefix=/usr/local/nginx \
--add-module=../agentzh-echo-nginx-module-9259898/ \
--add-module=../agentzh-memc-nginx-module-4007350/ \
注:前面一段是一些编译参数,后面add-module是添加模块
make -j2
make install
大爷的,又可能报错。没有nginx,logs目录访问权限
复制代码
代码如下:[alert]: could not open error log file: open() "/usr/local/nginx/logs/error.log" failed (13: Permission denied)
2011/03/21 06:09:33 [emerg] 24855#0: mkdir() "/usr/local/nginx/client_body_temp" failed (13: Permission denied)
解决办法:
复制代码
代码如下:sudo chmod a+rwx -R logs
sudo chmod a+rwx -R /usr/local/nginx
现在,差不多没问题了。
可以进入/usr/local/nginx/sbin/执行以下命令看是否成功:
nginx -v
5)、nginx自启动
编辑启动脚本:
复制代码
代码如下:sudo vim /etc/init.d/nginx
复制代码
代码如下:#! /bin/bash
#
# nginx Start up the nginx server daemon
#
# chkconfig: 2345 55 25
# Description: starts and stops the nginx web server
#
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: starts and stops the nginx web server
### END INIT INFO
# To install:
# copy this file to /etc/init.d/nginx
# shell> chkconfig --add nginx (RedHat)
# shell> update-rc.d -f nginx defaults (debian)
# To uninstall:
# shell> chkconfig --del nginx (RedHat)
# shell> update-rc.d -f nginx remove
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
NAME=nginx
DAEMON=/usr/local/nginx/sbin/$NAME
CONFIGFILE=/usr/local/nginx/conf/$NAME.conf
PIDFILE=/var/local/nginx/logs/$NAME.pid
ULIMIT=10240
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
echo "Starting $NAME ..."
ulimit -SHn $ULIMIT
$DAEMON -c $CONFIGFILE
}
do_stop() {
echo "Shutting down $NAME ..."
kill 'cat $PIDFILE'
}
do_reload() {
echo "Reloading $NAME ..."
kill -HUP 'cat $PIDFILE'
}
case "$1" in
start)
[ ! -f "$PIDFILE" ] && do_start || echo "nginx already running"
echo -e ".\ndone"
;;
stop)
[ -f "$PIDFILE" ] && do_stop || echo "nginx not running"
echo -e ".\ndone"
;;
restart)
[ -f "$PIDFILE" ] && do_stop || echo "nginx not running"
do_start
echo -e ".\ndone"
;;
reload)
[ -f "$PIDFILE" ] && do_reload || echo "nginx not running"
echo -e ".\ndone"
;;
*)
N=/etc/init.d/$NAME
echo "Usage: $N {start|stop|restart|reload}" >&2
exit 1
;;
esac
exit 0
红色部分,根据自己的路径修改。
6)、常用命令
重启nginx:service nginx restart
启动:service nginx start
关闭:service nginx stop
7)、linux常用命令
tar(z-用 gzip 对存档压缩或解压;x-从存档展开文件;v-详细显示处理的文件;f-指定存档或设备)
tar –zxvf nginx-0.8.54.tar.gz
ip查看
ifconfig
编译
make
安装编译好的源码包
make install
编辑文件
sudo gedit /etc/profile
修改根限:chmod说明(u:与文件属主拥有一样的权限[a:所有人];+:增加权限;rwx:可读可写可执行)
-R:递归所有目录和文件
sudo chmod a+rwx -R logs
检查是库是否安装成功
dpkg --list|grep openssl
下载安装库
sudo apt-get install libtool
检查服务启动是否正常
ps -ef|grep
查找openssl安装路径
whereis openssl
更新源
sudo apt-get update
更新已安装的包
sudo apt-get upgrade
相关文章
如何在Ubuntu系统中使用PPA? 在Ubuntu Linux 中使用PPA完全指南
什么是 PPA?为什么要使用它?使用 PPA 安全吗?如何正确使用 PPA?如何删除 PPA?这是一篇涵盖了在 Ubuntu 和其他 Linux 发行版中使用 PPA 遇到的几乎所有问题的深入的文2024-03-07Ubuntu22.04怎么安装Python 3.11? Ubuntu下载安装Python的图文教程
Ubuntu22.04系统需要使用Python软件,很多朋友不知道该怎么安装,今天我么就来分享Python软件下载以及安装的详细教程2024-03-07怎么用U盘安装Ubuntu20.04系统? 乌班图桌面版安装图文教程附下载
之前电脑安装的Centos7系统,但是在启动过程中遇到了文件异常,就开不了机了,现在想用U盘装Ubuntu系统,该怎么安装呢?详细请看下文图文安装教程,很详细适合小白新手操作2024-02-29Ubuntu如何访问Windows文件 Ubuntu访问Windows文件夹的方法
在使用Ubuntu Linux的过程中,有时我们需要访问存储在Windows系统中的文件或者文件夹,该怎么操作呢?详细请看下文介绍2024-02-03如何解决Ubuntu环境下解压中文显示乱码问题? Ubuntu解压中文乱码的多种
在Ubuntu下解压Windows下压缩文件时,会出现解压出的带中文文件名的文件名乱码,这大概率是因为buntu和Windows默认的编码不同,当然也有其他原因,详细请看下文介绍2024-01-09- Ubuntu怎么查看文件大小或文件夹大小?Ubuntu系统中,我们可以使用命令来查看给定目录或文件的大小,详细请看下文介绍2023-12-22
如何在Ubuntu上设置环境变量? ubuntu环境变量的三种设置方法
如何在Ubuntu上设置环境变量?环境变量是作用在操作系统中用来设置操作系统的一些参数,下面我们就来看看ubuntu环境变量的三种设置方法2023-12-22- 这篇文章主要为大家介绍了ubuntu配置静态地址方法详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2023-12-15
Ubuntu怎么安装VMware Tools? vmware tools安装详细图文教程
Ubuntu怎么安装VMware Tools?Ubuntu想要安装VMware Tools,该怎么操作呢?下面我们就来看看vmware tools安装详细图文教程2023-11-25- 这篇文章主要介绍了Ubuntu22.04安装SSH无法连接的问题及解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2023-10-23
最新评论