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

Ubuntu nginx 安装

2016-04-27 22:54 525 查看
卸载掉自带的nginx版本

如果迩是在ubuntun下安装nginx、建议先卸载掉自带的版本、太旧了、0.7的、uWsgi都不支持、还要打补丁、太麻烦了、如果是默认安装的话、一定是使用了apt-get的方式来安装的、那么莪们就使用apt-get的方式来卸载吧、

sudo apt-get --purge remove nginx


完成后再试下which nginx存在不、不存在就是已经成功卸了

还是从源码安装吧、这样可以不用管更新apt-get源之类的是否成功之类的、

首先去找个源码吧、目前官网的最新稳定版是1.2.6、所以输入个

wget http://nginx.org/download/nginx-1.2.6.tar.gz

获取到当前目录、然后再解压啪啪的tar -zxf xxxx.tar.gz

然后就安装吧、从源码安装三步曲如果没有意外的话是狠顺利的、

./configure
make
sudo make install


先执行./configure后别急着往下执行、看看配置不是有有错了、如果不看清楚的话、执行make肯定会出问题、如果迩在make的时候看到出现

make: * No rule to make target
build', needed by
default’. Stop.这种现象、迩回头看看./configure的出错信息是不是没装某个组件、比如没装

伪静态模块需要pcre库、这是相常见的问题、没装就装上吧、目前pcre最新版本为8.12、如果迩想下载的话最好选择tar.gz的、当然官网也提供了压缩率更高的

tar.bz2格式、不过解压稍微麻烦点、需要用到bzip2这个工具、先解压、再解包、xxx的、不过咱网速也不慢、嫌麻烦还是老老实实用tar.gz格式吧

bzip2 -d xxx.tar.bz2
tar -xf xxx.tar
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.12.tar.gz[/code] 
搞定咯、再运行一次./configure、再make、make install、问题不大、注意make install要root权限、如果是ubuntu的话可以用sudo暂时调用root权限、

Linux下编译安装PCRE库

1.下载PCRE包

首先去官网下载pcre的安装包

如果通过FTP的方式,下载地址为:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/

如果通过http的方式,下载地址为:http://sourceforge.net/projects/pcre/files/pcre/

目前最新的版本为8.32,linux对应的安装包名称为:pcre-8.32.tar.gz。

2.把安装包上传到服务器,然后解压

[root@localhost local]# tar -zxvf pcre-8.32.tar.gz


解压之后在当前目录下生成了一个文件夹:pcre-8.32

3.配置

[root@localhost pcre-8.32]# ./configure


配置完之后控制台会打印出pcre配置的摘要信息

pcre-8.32 configuration summary:

Install prefix .................. : /usr/local
C preprocessor .................. : gcc -E
C compiler ...................... : gcc
C++ preprocessor ................ : g++ -E
C++ compiler .................... : g++
Linker .......................... : /usr/bin/ld
C preprocessor flags ............ :
C compiler flags ................ : -O2 -fvisibility=hidden
C++ compiler flags .............. : -O2 -fvisibility=hidden -fvisibility-inlines-hidden
Linker flags .................... :
Extra libraries ................. :

Build 8 bit pcre library ........ : yes
Build 16 bit pcre library ....... : no
Build 32 bit pcre library ....... : no
Build C++ library ............... : yes
Enable JIT compiling support .... : no
Enable UTF-8/16/32 support ...... : no
Unicode properties .............. : no
Newline char/sequence ........... : lf
\R matches only ANYCRLF ......... : no
EBCDIC coding ................... : no
EBCDIC code for NL .............. : n/a
Rebuild char tables ............. : no
Use stack recursion ............. : yes
POSIX mem threshold ............. : 10
Internal link size .............. : 2
Match limit ..................... : 10000000
Match limit recursion ........... : MATCH_LIMIT
Build shared libs ............... : yes
Build static libs ............... : yes
Use JIT in pcregrep ............. : no
Buffer size for pcregrep ........ : 20480
Link pcregrep with libz ......... : no
Link pcregrep with libbz2 ....... : no
Link pcretest with libedit ...... : no
Link pcretest with libreadline .. : no
Valgrind support ................ : no
Code coverage ................... : no


4.编译

执行make操作:

执行make结果如下:

chesian@ubuntu:/usr/local/src/pcre2-10.20$ sudo make
rm -f src/pcre2_chartables.c
ln -s /usr/local/src/pcre2-10.20/src/pcre2_chartables.c.dist /usr/local/src/pcre2-10.20/src/pcre2_chartables.c
make  all-am
make[1]: Entering directory '/usr/local/src/pcre2-10.20'
CC       src/libpcre2_8_la-pcre2_auto_possess.lo
CC       src/libpcre2_8_la-pcre2_compile.lo
CC       src/libpcre2_8_la-pcre2_config.lo
CC       src/libpcre2_8_la-pcre2_context.lo
CC       src/libpcre2_8_la-pcre2_dfa_match.lo
CC       src/libpcre2_8_la-pcre2_error.lo
CC       src/libpcre2_8_la-pcre2_jit_compile.lo
CC       src/libpcre2_8_la-pcre2_maketables.lo
CC       src/libpcre2_8_la-pcre2_match.lo
CC       src/libpcre2_8_la-pcre2_match_data.lo
CC       src/libpcre2_8_la-pcre2_newline.lo
CC       src/libpcre2_8_la-pcre2_ord2utf.lo
CC       src/libpcre2_8_la-pcre2_pattern_info.lo
CC       src/libpcre2_8_la-pcre2_serialize.lo
CC       src/libpcre2_8_la-pcre2_string_utils.lo
CC       src/libpcre2_8_la-pcre2_study.lo
CC       src/libpcre2_8_la-pcre2_substitute.lo
CC       src/libpcre2_8_la-pcre2_substring.lo
CC       src/libpcre2_8_la-pcre2_tables.lo
CC       src/libpcre2_8_la-pcre2_ucd.lo
CC       src/libpcre2_8_la-pcre2_valid_utf.lo
CC       src/libpcre2_8_la-pcre2_xclass.lo
CC       src/libpcre2_8_la-pcre2_chartables.lo
CCLD     libpcre2-8.la
ar: `u' modifier ignored since `D' is the default (see `U')
CC       src/libpcre2_posix_la-pcre2posix.lo
CCLD     libpcre2-posix.la
ar: `u' modifier ignored since `D' is the default (see `U')
CC       src/pcre2grep-pcre2grep.o
CCLD     pcre2grep
CC       src/pcre2test-pcre2test.o
CCLD     pcre2test
make[1]: Leaving directory '/usr/local/src/pcre2-10.20'


5.安装

执行make install操作:

make install结束后pcre编译安装流程就结束了。

nginx算是安装好了、不过还不能用、进入nginix目录、一般来说./configure不指定目录安装的话是安装在/usr/local/nginx、如果迩想指定其它目录用上–prefix=xxx目录、如果迩是安装在默认目录的话、执行个软链接命令把nginx连去/usr/bin目录下、

sudo ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx

注意啦、root权限、相信也没多大问题了、然后在哪里都可以运行nginx了、执行一下nginx -v如果看到版本号就算是安装完成了、

然后是启动nginx

如果运行nginx的话启动出错、遇到error while loading shared libraries: libpcre.so.0: cannot open shared object file: No such file or directory

那么又是系统找不到某某库、把/usr/local下做个软链接搬过来就是了

sudo ln -s /usr/local/lib/libpcre.so.0 /usr/lib/libpcre.so.0

好了、启动nginx吧、想验证一下、用浏览器打开localhost:80咯、看看是否看到了nginx的欢迎页面、如果行就OK啦

启动nginx

chesian@ubuntu:/usr/local/nginx$ sudo ./sbin/nginx


如果启动出错、像这样的信息

nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()


sudo /usr/local/sbin/nginx    (启动)
/usr/local/sbin/nginx -s stop (停止)
/usr/local/sbin/nginx -s reload (重启)


nginx 安装常见问题:

1、src/core/ngx_regex.h:15:18: fatal error: pcre.h: No such file or directory

make nginx报错

解决方案:apt-get install libpcre3-dev

2、缺少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= 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  


3、缺少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,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   


默认nginx安装的目录

默认nginx安装的目录在/usr/local/nginx下,包括:

/usr/local/nginx/sbin #控制nginx启动文件

/usr/local/nginx/conf #配置文件

/usr/local/nginx/html #默认网页文件

/usr/local/nginx/logs #日志文件

Nginx安装总结

nginx依赖以下模块:

l gzip模块需要 zlib 库

l rewrite模块需要 pcre 库

l ssl 功能需要openssl库

1.1.安装pcre

1. 获取pcre编译安装包,在http://www.pcre.org/上可以获取当前最新的版本

解压缩pcre-xx.tar.gz包。

进入解压缩目录,执行./configure。

make & make install

1.2.安装openssl

1. 获取openssl编译安装包,在http://www.openssl.org/source/上可以获取当前最新的版本。

解压缩openssl-xx.tar.gz包。

进入解压缩目录,执行./config。

make & make install

1.3.安装zlib

1. 获取zlib编译安装包,在http://www.zlib.net/上可以获取当前最新的版本。

解压缩openssl-xx.tar.gz包。

进入解压缩目录,执行./configure。

make & make install

1.4.安装nginx

1. 获取nginx,在http://nginx.org/en/download.html上可以获取当前最新的版本。

解压缩nginx-xx.tar.gz包。

进入解压缩目录,执行./configure

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