linux下nginx安装、启动、停止,设置开机启动

4 篇文章 0 订阅

安装、启动、停止:

http://note.youdao.com/noteshare?id=122fb0fe2ff421d949baa066e157a2b9&sub=E10E967EF37246339B3B85050803388E

开始前,请确认gcc g++开发类库是否装好,默认已经安装。

  ububtu平台编译环境可以使用以下指令

apt-get install build-essential apt-get install libtool

  centos平台编译环境使用如下指令

  安装make:

yum -y install gcc automake autoconf libtool make

  安装g++:

yum install gcc gcc-c++

下面正式开始:

一、选定安装文件目录

  可以选择任何目录,本文选择 cd /usr/local/src

1 cd /usr/local/src

cd /usr/local/src

二、安装PCRE库

  ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/ 下载最新的 PCRE 源码包,使用下面命令下载编译和安装 PCRE 包:(本文参照下载文件版本:pcre-8.37.tar.gz 经过验证未发现这个版本,若想下载最新版本请打开上面网址。本文选择pcre-8.39.tar.gz)

cd /usr/local/src wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz tar -zxvf pcre-8.37.tar.gz cd pcre-8.34 ./configure make make install

三、安装zlib库

  http://zlib.net/zlib-1.2.11.tar.gz 下载最新的 zlib 源码包,使用下面命令下载编译和安装 zlib包:(本文参照下载文件版本:zlib-1.2.8.tar.gz 经过验证未发现这个版本,若想下载最新版本请打开上面网址。本文选择zlib-1.2.11.tar.gz )

cd /usr/local/src wget http://zlib.net/zlib-1.2.11.tar.gz tar -zxvf zlib-1.2.11.tar.gz cd zlib-1.2.11 ./configure make make install

四、安装openssl(某些vps默认没装ssl)

cd /usr/local/src wget https://www.openssl.org/source/openssl-1.0.1t.tar.gz tar -zxvf openssl-1.0.1t.tar.gz

五、安装nginx

  Nginx 一般有两个版本,分别是稳定版和开发版,您可以根据您的目的来选择这两个版本的其中一个,下面是把 Nginx 安装到 /usr/local/nginx 目录下的详细步骤:

cd /usr/local/src wget http://nginx.org/download/nginx-1.1.10.tar.gz tar -zxvf nginx-1.1.10.tar.gz cd nginx-1.1.10

./configure

make

make install

ngingx安装错误 ./configure: error: the HTTP rewrite module requires the PCRE library.

有时候,我们需要单独安装nginx,来处理大量的下载请求。单独在Centos5安装nginx遇到的rewrite和HTTP cache错误解决办法:

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

tar -zxvf nginx-0.8.33.tar.gz

cd nginx-0.8.33

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

安装Nginx时报错

./configure: error: the HTTP rewrite module requires the PCRE library.

安装pcre-devel解决问题

yum -y install 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=<path> options.

解决办法:

yum -y install openssl openssl-devel

总结:

yum -y install pcre-devel openssl openssl-devel

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

make

make install

 

 

若使用红帽执行yum过程中出现如下错误:

Loaded plugins: product-id, refresh-packagekit, security, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Setting up Install Process

Nothing to do

 

以下命令直接把源文件下载到/etc/yum.repos.d/目录

# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

编辑新下载的源文件,修改其中的版本号

# vim CentOS-Base.repo

编辑文件,把文件里面的$releasever全部替换为版本号:6最后保存

:%s/$releasever/6/g

保存文件即可

:wq

然后就可以正常使用yum了

 

 

先将nginx加入环境变量,便于在任何地方直接使用nginx命令

vi /etc/profile

shift+g调到最后一行,按a或者i进入编辑模式

然后esc,按:wq保存退出

source /etc/profile 让配置文件重新生效一下

启动操作

nginx -c /usr/local/nginx/conf/nginx.conf

(如果没配置环境变量,nginx命令要改成nginx在你服务器的安装配置位置)

查询nginx主进程号

ps -ef | grep nginx

重启

nginx -s reload

停止

nginx -s stop

检查配置文件是否正确

nginx -t

设置开机启动:

http://note.youdao.com/noteshare?id=3511d1e5c17809f91cd0fef8e364c8eb&sub=EDCB0D1CD4724B40BD4E7D9762D27EB3

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值