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

Centos6编译安装Nginx服务

2018-01-06 18:20 246 查看
【1】查看当前系统环境

[root@www ~]# cat /etc/redhat-release
CentOS release 6.3 (Final)
[root@www ~]# uname -r
2.6.32-279.el6.x86_64
[root@www ~]# uname -m
x86_64


【2】安装Nginx所需要的pcre库,来支持Nginx具备URI重写功能的rewrite模块

注意 devel的软件包必须要安装

//采用yum安装方式来安装pcre
[root@www ~]# yum install pcre pcre-devel -y
//查看安装后结果
[root@www ~]# rpm -qa pcre pcre-devel
pcre-7.8-7.el6.x86_64
pcre-devel-7.8-7.el6.x86_64
//检查Nginx基础依赖包pcre-devel openssl-devel
[root@www ~]# rpm -qa pcre-devel pcre
pcre-7.8-7.el6.x86_64
pcre-devel-7.8-7.el6.x86_64


【3】安装openssl-devel来使Nginx提供HTTPS服务

[root@www ~]# yum install openssl openssl-devel -y
//安装后检查一下
[root@www ~]# rpm -qa openssl openssl-devel
openssl-1.0.1e-57.el6.x86_64
openssl-devel-1.0.1e-57.el6.x86_64


【4】安装Nginx

//创建一个工具目录来存放软件
[root@www tack]# mkdir -p /home/tack/tools
//下载安装包(或者http://nginx.org/download/)
[root@www tool]# wget -q http://nginx.org/download/nginx-1.6.3.tar.gz [root@www tool]# ls -l nginx-1.6.3.tar.gz
-rw-r--r-- 1 root root 805253 4月   8 2015 nginx-1.6.3.tar.gz
//**注意** 对于useradd命令
//-M:不创建家目录
//-s:指定用户登陆时使用的shell,nologin就是登陆不了
[root@www tool]# useradd nginx -s /sbin/nologin -M
//**注意**对于tar命令
//-v  显示压缩或解压的过程
//-x   解开压缩文件
//-f   目标文件名
//这里就不显示过程 直接解压就好
[root@www tool]# tar xf nginx-1.6.3.tar.gz
//**注意**对于编译Nginx软件时候
//--user 设置进程用户权限
//--group 设置进程用户组权限
// --with-http_stub_status_module  激活状态信息
//--with-http_ssl_module 激活ssl功能
[root@www nginx-1.6.3]# ./configure
--user=nginx
--group=nginx
--with-http_stub_status_module
--with-http_ssl_module
[root@www nginx-1.6.3]# make && make install
//**注意**建立软连接方便访问,也方便升级。如果以后要升级就更换该链接
[root@www tool]# ln -s /application/nginx-1.6.3 /application/nginx


【5】启动并检查安装结果

//启动前检查配置文件语法
[root@www application]# /application/nginx/sbin/nginx  -t
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
//启动Nginx服务
[root@www ~]# /application/nginx/sbin/nginx
//查看Nginx服务对应的端口是否成功
[root@www ~]# lsof -i:80
COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   5775  root    6u  IPv4  34757      0t0  TCP *:http (LISTEN)
nginx   5776 nginx    6u  IPv4  34757      0t0  TCP *:http (LISTEN)


【6】Nginx启动与关闭

//启动:
[root@www ~]# /application/nginx/sbin/nginx
//停止/重新加载:
[root@www ~]# /application/nginx/sbin/nginx
-s stop(quit、reload)
//验证配置文件是否合法:
[root@www ~]# /application/nginx/sbin/nginx -t
//命令帮助:
[root@www ~]# /application/nginx/sbin/nginx -h


目录截图



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