Linux(centos)安装nginx

1.安装编译环境以及第三方开发包。

[root@VM_0_16_centos ~]# yum -y install  gcc gcc-c++
[root@VM_0_16_centos ~]# yum -y install  pcre pcre-devel
[root@VM_0_16_centos ~]# yum -y install  zlib zlib-devel
[root@VM_0_16_centos ~]# yum -y install  openssl openssl-devel

Gcc-c++:源代码编译环境。

PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。

Zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。

OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。

2.把nginx源码包上传到服务器,并解压到指定位置(我直接解压到当前目录)。

[root@VM_0_16_centos ~]# tar -zxvf nginx-1.9.5.tar.gz 

参数解释:tar -zxvf(解压命令,z:表示此压缩包是被 gzip 压缩过的,所以解压时需要用 gunzip 解压,x: 从 tar 包中把文件提取出来,v : 显示详细信息,f:指定被处理的文件)。

3.进入解压的目录。

[root@VM_0_16_centos ~]# cd nginx-1.9.5/
[root@VM_0_16_centos nginx-1.9.5]# 

4.configure命令对安装软件进行配置。

[root@RedHat tmp]# ./configure --prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/tmp/nginx/client_body --http-proxy-temp-path=/tmp/nginx/proxy --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --http-fastcgi-temp-path=/tmp/nginx/fastcgi --pid-path=/var/run/nginx.pid --with-http_stub_status_module --with-http_ssl_module --with-http_ssl_module

 

./configure是源代码安装的第一步,主要的作用是对即将安装的软件进行配置,检查当前的环境是否满足要安装软件的依赖关系。

5.编译。

[root@VM_0_16_centos nginx-1.9.5]# make
[root@VM_0_16_centos nginx-1.9.5]# make install

6.安装完成后检验配置文件是否正确 nginx -t

[root@VM_0_16_centos nginx-1.9.5]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] mkdir() "/tmp/nginx/client_body" failed (2: No such file or directory)
nginx: configuration file /etc/nginx/nginx.conf test failed
[root@VM_0_16_centos nginx-1.9.5]# 

此时发现:

nginx: [emerg] mkdir() "/tmp/nginx/client_body" failed (2: No such file or directory)

需要建立没有的文件夹:

[root@VM_0_16_centos nginx-1.9.5]# mkdir -p /tmp/nginx/client_body
[root@VM_0_16_centos nginx-1.9.5]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful 

此时才正确安装。

7.启动nginx并检测是否启动。

[root@VM_0_16_centos nginx-1.9.5]# nginx
[root@VM_0_16_centos nginx-1.9.5]# netstat -antp | grep :80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      

已经完成正常启动。

8.浏览器访问服务器。

Perfect,顺利完成。

第一次写,勿喷

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值