Ubuntu下安装nginx的步骤分享

教程大全 2026-01-08 16:00:46 浏览

3)、进入相关目录进行以下操作

复制代码

代码如下:

./configuremakesudo make install

如果你运气好的话,一切ok,不过...........哈哈。Ubuntu默认的策略是什么库都不装,依赖的库都需要自已手工安装搞定。 一般都会出错的,那么我们来看看可能出现的问题。 解决方法:下载安装pcre-8.31解决问题,解压后对pcre进行如下操作

复制代码

代码如下:

sudo wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.31.tar.gzsudo tar -xzvf pcre-8.31.tar.gzcd /usr/local/src/pcre-8.31./configuremakesudo make install

运气好一次通过,运气不好,make pcre时会出错

复制代码

代码如下:

libtool: compile: unrecognized option `-DHAVE_CONFIG_H'libtool: compile: Try `libtool --help' for more information.make[1]: *** [pcrecpp.lo] Error 1make[1]: Leaving Directory `/usr/local/src//pcre-8.31'make: *** [all] Error 2root@wolfdog-virtual-machine:~/work/pcre-8.12$ libtool -help -DHAVE_CONFIG_HThe program 'libtool' is currently not installed. You can install it by typing:sudo apt-get install libtool

解决方法:需要先安装libtool和gcc-c++ 大爷啊~~~这时候可能又会报错啊,坑爹啊~~~

复制代码

代码如下:

./configure: error: the HTTP Cache module requires md5 functionsfrom 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= options.

复制代码

代码如下:

./configure: error: the HTTP gzip module requires the Zlib library.You can either disable the module by using --without-http_gzip_moduleoption, or install the zlib library into the system, or build the zlib librarystatically from the source with nginx by using --with-zlib= option.

解决办法:少什么就安装什么呗。 4)、解决了以上问题,编译nginx就没啥问题了。下面安装。(附加安装插件的方法)

复制代码

代码如下:

sudo wget-O echo-nginx-module.tar.gzsudo wget-O memc-nginx-module.tar.gzsudo tar -xzvf echo-nginx-module.tar.gzsudo 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 -j2make 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 logssudo chmod a+rwx -R /usr/local/nginx

可以进入/usr/local/nginx/sbin/执行以下命令看是否成功:

复制代码

代码如下:

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 removePATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/binNAME=nginxDAEMON=/usr/local/nginx/sbin/$NAMECONFIGFILE=/usr/local/nginx/conf/$NAME.confPIDFILE=/var/local/nginx/logs/$NAME.pidULIMIT=10240set -e[ -x "$DAEMON" ] || exit 0do_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" instart)[ ! -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_starTecho -e ".\ndone";;reload)[ -f "$PIDFILE" ] && do_reload || echo "nginx not running"echo -e ".\ndone";;*)N=/etc/init.d/$NAMEecho "Usage: $N {start|stop|restart|reload}" >&2exit 1;;esacexit 0

红色部分,根据自己的路径修改。 6)、常用命令 Ubuntu 7)、linux常用命令 tar(z-用 gzip 对存档压缩或解压;x-从存档展开文件;v-详细显示处理的文件;f-指定存档或设备) 修改根限:chmod说明(u:与文件属主拥有一样的权限[a:所有人];+:增加权限;rwx:可读可写可执行) 检查是库是否安装成功 检查服务启动是否正常

本文版权声明本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,请联系本站客服,一经查实,本站将立刻删除。

发表评论

热门推荐