一键安装nginx

系统版本

CentOS release 6.9 (Final)

2.6.32-696.el6.x86_64 x86_64


#安装pcre pcre-devel 

[root@web01 ~]# yum install pcre pcre-devel -y  


 #检查pcre pcre-devel

[root@web01 ~]# rpm -qa pcre pcre-devel 

pcre-7.8-7.el6.x86_64

pcre-devel-7.8-7.el6.x86_64

 #安装openssl-devel,使用nginx必须安装这个软件来支持

[root@web01 nginx-1.6.3]# yum install openssl-devel -y


#检查openssl-devel openssl

[root@web01 nginx-1.6.3]# rpm -qa openssl-devel openssl  #检查openssl-devel openssl

openssl-1.0.1e-57.el6.x86_64

openssl-devel-1.0.1e-57.el6.x86_6


#添加用户

useradd oldboy

#创建tools目录

mkdir /home/oldboy/tools

cd /home/oldboy/tools/

#下载nginx,具体需要什么版本自己可以到 http://nginx.org官网下载

wget -q http://nginx.org/download/nginx-1.6.3.tar.gz 


#查看到下载的nginx

[root@web01 tools]# ll

总用量 788

-rw-r--r-- 1 root root 805253 4月   8 2015 nginx-1.6.3.tar.gz


  #解压压缩包

[root@web01 tools]# tar xf nginx-1.6.3.tar.gz 


#cd到nginx-1.6.3目录下

cd nginx-1.6.3


#创建application目录存放软件

mkdir /application


#创建虚拟用户

[root@web01 application]# useradd www -s /sbin/nologin -M  


#编译安装nginx

./configure --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --prefix=/application/nginx-1.6.3/


#查看编辑是否成功

[root@web01 nginx-1.6.3]# echo $?   #返回

0表示配置成功

0

clipboard.png


[root@web01 nginx-1.6.3]# make    #返回0直接就用make编译

clipboard.png

同样是echo $?是返回0正常


#安装

[root@web01 nginx-1.6.3]# make install 


#安装完成之后,为了以后更新软件方便,需要创建一个软链接给nginx

[root@web01 nginx-1.6.3]# ln -s /application/nginx-1.6.3/ /application/nginx

[root@web01 nginx-1.6.3]# cd /application/


[root@web01 application]# ll

总用量 4

lrwxrwxrwx 1 root root   25 2月  27 11:13 nginx -> /application/nginx-1.6.3/

drwxr-xr-x 6 root root 4096 2月  27 11:12 nginx-1.6.3


#启动nginx

[root@web01 application]# /application/nginx/sbin/nginx

[root@web01 ~]# /application/nginx/sbin/nginx -t   #检查语法对不对

1. 1. nginx: the configuration file /application/nginx-1.6.3//conf/nginx.conf syntax is ok

nginx: configuration file /application/nginx-1.6.3//conf/nginx.conf test is successful


[root@web01 application]# netstat -lntup |grep 80   #查看nginx端口是否启动

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      45878/nginx     



在自己浏览器查看是否成功

clipboard.png


一键安装命令如下:

[root@web01 scripts]# cat nginx.sh 

#!/bin/bash


export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

LANG=en

yum install pcre pcre-devel -y

yum install openssl-devel -y

useradd oldboy

mkdir /home/oldboy/tools

cd /home/oldboy/tools/

wget -q http://nginx.org/download/nginx-1.6.3.tar.gz

tar xf nginx-1.6.3.tar.gz

cd nginx-1.6.3

mkdir /application

useradd www -s /sbin/nologin -M

./configure --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --prefix=/application/nginx-1.6.3/

echo $?

make

echo $?

make install

ln -s /application/nginx-1.6.3/ /application/nginx

cd /application/

/application/nginx/sbin/nginx

/application/nginx/sbin/nginx -t

netstat -lntup |grep 80


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章