安装nginx

1. 下载 nginx
http://nginx.org/download/上下载相应的版本(或者http://nginx.org/download/nginx-1.10.2.tar.gz
直接在Linux上用命令下载)

[root@besttest tomcat6]# wget http://nginx.org/download/nginx-1.10.2.tar.gz
-bash: wget: command not found

安装wget:
yum -y install wget

在执行下载nginx
这里写图片描述

通过find / -name nginx-1.10.2.tar.gz 确认下载文件的路径

2. 解压

解压命令:
tar -zxvf nginx-1.10.2.tar.gz

mv nginx-1.10.2 nginx 重命名下

3.编译

cd nginx

执行 ./configure 生成Makefile时遇到的问题
这里写图片描述
./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库
解决方法:
yum install -y pcre pcre-devel

还有可能出现:
错误提示:./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= options.

解决办法:
yum -y install openssl openssl-devel

执行make 编译

4. 安装

执行make install 命令进行编译时遇到的问题:
这里写图片描述
问题原因: 直接把安装包重命名成nginx了,安装文件没有路径了。

解决办法如下:

删除nginx 文件夹
rm -rf nginx

重新解决源码
tar -zxvf nginx-1.10.2.tar.gz

cd /usr/local/nginx-1.10.2

生成Makefile文件

./configure --prefix=/usr/local/nginx

编译源码
make

安装
make install

5. 启动nginx 服务

[root@besttest ~]# whereis nginx
nginx: /usr/local/nginx

这里写图片描述

启动命令./nginx , 遇到端口已绑定
这里写图片描述

netstat -ntpl 查看到80端口被占用了
这里写图片描述

解决方法:
kill 1226 进程

执行./nginx 启动服务

这里写图片描述

还可以通过ps -ef |grep nginx 查询nginx主进程号
这里写图片描述

6. 停止服务
./nginx -s stop

7. 补充说明

因安装nginx 时的系统环境不同 , 可能需要依赖的库有所不同,先归纳下nginx安装需要依赖的库:
选首先安装这几个软件:GCC,PCRE(Perl Compatible Regular Expression),zlib,OpenSSL。
Nginx是C写的,需要用GCC编译;Nginx的Rewrite和HTTP模块会用到PCRE;Nginx中的Gzip用到zlib;
用命令“ gcc”,查看gcc是否安装;如果出现“gcc: no input files”信息,说明已经安装好了。
否则,就需要用命令“ yum -y install gcc”,进行安装了!一路可能需要多次输入y,进行确认。
安装好后,可以再用命令“gcc”测试,或者用命令“ gcc -v”查看其版本号。
同样方法,用如下命令安装PCRE,zlib,OpenSSL(其中devel,是develop开发包的意思):

yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值