安装部署nginx

原创 2015年08月11日 10:54:33

1:选定源码目录

 

选定目录 /usr/local/

 

2:安装PCRE库

cd /usr/local/
[root@ser6-70 local]# wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
--2015-08-10 18:14:53--  ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
           => “pcre-8.36.tar.gz”
Resolving ftp.csx.cam.ac.uk... 131.111.8.115
Connecting to ftp.csx.cam.ac.uk|131.111.8.115|:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done.    ==> PWD ... done.
==> TYPE I ... done.  ==> CWD (1) /pub/software/programming/pcre ... done.
==> SIZE pcre-8.36.tar.gz ... 2009464
==> PASV ... done.    ==> RETR pcre-8.36.tar.gz ... done.
Length: 2009464 (1.9M) (unauthoritative)
 
100%[===================================================================================================================>] 2,009,464    437K/s   in 4.9s    
 
2015-08-10 18:15:20 (401 KB/s) - “pcre-8.36.tar.gz” saved [2009464]
 
tar -xvf pcre-8.36.tar.gz  
cd pcre-8.36
./configure 
make
make install


假如./configure报错:configure: error: You need a C++ compiler for C++ support

需要yum install -y gcc gcc-c++

 

3:安装zlib库

cd /usr/local/  
[root@ser6-70 local]# wget http://zlib.net/zlib-1.2.8.tar.gz
--2015-08-10 18:19:44--  http://zlib.net/zlib-1.2.8.tar.gz
Resolving zlib.net... 69.73.132.10
Connecting to zlib.net|69.73.132.10|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 571091 (558K) [application/x-gzip]
Saving to: “zlib-1.2.8.tar.gz”
 
100%[===================================================================================================================>] 571,091     12.8K/s   in 25s     
 
2015-08-10 18:20:11 (22.1 KB/s) - “zlib-1.2.8.tar.gz” saved [571091/571091]
 
tar -zxvf zlib-1.2.8.tar.gz cd zlib-1.2.8
cd zlib-1.2.8
./configure
make
make install


4:安装ssl

 

cd /usr/local/
[root@ser6-70 ~]# wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
--2015-08-11 09:25:50--  http://www.openssl.org/source/openssl-1.0.1c.tar.gz
Resolving www.openssl.org... 194.97.150.234, 2001:608:c00:180::1:ea
Connecting to www.openssl.org|194.97.150.234|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 4457113 (4.2M) [application/x-gzip]
Saving to: “openssl-1.0.1c.tar.gz”
 
 5% [=====>                                                                                                              ] 247,230     8.09K/s  eta 7m 33s  
 5% [=====>                                                                                                              ] 251,574     7.33K/s  eta 7m 33s  
 5% [=====>                                                                                                              ] 258,814     8.50K/s  eta 7m 32s  
 
 
 
 5% [=====>                                                                                                              ] 258,814     7.85K/s  eta 7m 32s  
 5% [=====>                                                                                                              ] 266,054     8.30K/s  eta 7m 45s  
 6% [======>                                                                                                             ] 283,430     8.95K/s  eta 7m 42s  
 
100%[===================================================================================================================>] 4,457,113   5.58K/s   in 10m 44s 
 
2015-08-11 09:36:35 (6.76 KB/s) - “openssl-1.0.1c.tar.gz” saved [4457113/4457113]
 
tar -zxvf openssl-1.0.1c.tar.gz
cd openssl-1.0.1c
./config
make
make install


5:安装nginx

 

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

 

cd /usr/local/

 

[root@ser6-70 ~]# wget http://nginx.org/download/nginx-1.2.8.tar.gz
--2015-08-11 09:54:31--  http://nginx.org/download/nginx-1.2.8.tar.gz
Resolving nginx.org... 206.251.255.63, 2606:7100:1:69::3f
Connecting to nginx.org|206.251.255.63|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 730589 (713K) [application/octet-stream]
Saving to: “nginx-1.2.8.tar.gz”
 
100%[===================================================================================================================>] 730,589     23.7K/s   in 39s     
 
2015-08-11 09:55:11 (18.4 KB/s) - “nginx-1.2.8.tar.gz” saved [730589/730589]
tar -zxvf nginx-1.2.8.tar.gz
cd nginx-1.2.8  
./configure --prefix=/usr/local/nginx 
make
make install


6:启动nginx

确保系统的 80 端口没被其他程序占用,

/usr/local/nginx/sbin/nginx

 

[root@ser6-70 nginx-1.2.8]# /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

 

假如报上面这个错误,请参考:http://blog.csdn.net/yabingshi_tech/article/details/47416289

 

检查是否启动成功:

netstat -ano|grep 80 有结果输入说明启动成功,如:

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      off (0.00/0/0)

 

 #注意:如果防火墙已关闭的话,需要开放80端口。

 

打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。

  


7 设置开机自动启动


首先,在linux系统的/etc/init.d/目录下创建nginx文件,使用如下命令:
vi /etc/init.d/nginx
在脚本中添加:

#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# it is v.0.0.2 version.
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
#              It has a lot of features, but it's not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx/sbin/nginx
nginx_config=/usr/local/nginx/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="nginx"
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
   echo "nginx already running...."
   exit 1
fi
   echo -n $"Starting $prog: "
   daemon $nginxd -c ${nginx_config}
   RETVAL=$?
   echo
   [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
   return $RETVAL
}
# Stop nginx daemons functions.
stop() {
        echo -n $"Stopping $prog: "
        killproc $nginxd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx $nginx_pid 
}
# reload nginx service functions.
reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
}
# See how we were called.
case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload)
        reload
        ;;
restart)
        stop
        start
        ;;
status)
        status $prog
        RETVAL=$?
        ;;
*)
        echo $"Usage: $prog {start|stop|restart|reload|status|help}"
        exit 1
esac
exit $RETVAL

注意:nginxd=/usr/local/nginx/sbin/nginx,nginx_config=/usr/local/nginx/conf/nginx.conf请根据自己服务器的实际情况进行修改。

chmod a+x /etc/init.d/nginx 

将nginx加入到rc.local文件中,这样开机的时候nginx就默认启动了
vi /etc/rc.local
添加
/etc/init.d/nginx start   
保存并退出

现在就可以用service nginx stop/start看能否关闭/启动nginx.
测试机器的话,可以重启下服务器,验证下是否实现了nginx的自启动。


--本篇文章转自:http://www.cnblogs.com/zhuhongbao/archive/2013/06/04/3118061.html

http://blog.163.com/qsc0624@126/blog/static/140324073201312734548701/

并做了些许改动。

 

 

VB环境下压缩数据流播放技术(2)

 3.4.MPEG数据流的缩放显示    放大或缩小MPEG图像是各种多媒体播放软件中常用的图像显示处理手段。VisualBasic中对于静态图片进行缩放处理可以使用Image控件,将控件的Stret...
  • ghj1976
  • ghj1976
  • 2000-12-14 20:26:00
  • 1928

AIX7.1安装Nginx 1.13的方法

NGINX近两年的使用范围非常广泛,既可以作为HTTP负载均衡器,还可以作为PHP服务器,还能做HTTPS服务器,用途非常广泛,体积非常小巧,性能很高。很多Linux的Web服务器都部署了nginx。...
  • lvshaorong
  • lvshaorong
  • 2018-02-28 16:57:54
  • 231

Nginx的配置和使用

本文主要介绍前端开发的nginx代理配置
  • ZHBR_F1
  • ZHBR_F1
  • 2017-05-23 21:27:01
  • 1364

在 nginx 中部署 angular 应用

最近使用Angular做了第一个应用,但是网上的教程大多是教如何开发,部署相对较少,所以这里就简单记录一下如何在nginx中部署Angular应用。 注:Angular应用可以编译成静态页面,然后...
  • t894690230
  • t894690230
  • 2017-10-15 22:19:18
  • 2375

Nginx的安装与部署

1:安装工具包 wget、vim和gccyum install -y wget yum install -y vim-enhanced yum install -y make cmake gc...
  • yougoule
  • yougoule
  • 2017-10-09 20:00:13
  • 3523

基于nginx的静态网页部署

背景:一序列的html网页需要部署基于nginx的部署:本文采用的基于openresty的nginx 配置。 简单地配置 Nginx 的配置文件,以便在启动 Nginx 时去启用这些配置即可实现对于...
  • ljp1919
  • ljp1919
  • 2017-06-18 13:58:25
  • 7647

Nginx在Linux下的安装与配置

这是本人在安装与配置nginx时所做的一些记录,可能有些地方写得不够详细。 nginx依赖以下一些软件库,在安装之前请确保安装了这些软件库,它们包括:gcc,openssl,zlib,pcre(可通...
  • forever_forest
  • forever_forest
  • 2013-05-30 14:53:24
  • 50232

安装部署nginx

1:选定源码目录   选定目录 /usr/local/   2:安装PCRE库 cd /usr/local/ [root@ser6-70 local]# wget ftp://ftp.csx.cam....
  • YABIGNSHI
  • YABIGNSHI
  • 2015-08-11 10:54:33
  • 1485

Nginx配置详解

出自:http://www.cnblogs.com/knowledgesea/p/5175711.html 序言 Nginx是lgor Sysoev为俄罗斯访问量第...
  • zwhfyy
  • zwhfyy
  • 2017-09-07 09:24:51
  • 356

unbunt系统安装Nginx

目录 [隐藏] 1 安装nginx2 启动nginx3 配置php和mysql 3.1 安装Php和mysql3.2 安装FastCgi3.3 配置 nginx 4 安装nginx ...
  • ytp151730
  • ytp151730
  • 2014-01-20 14:35:32
  • 423
收藏助手
不良信息举报
您举报文章:安装部署nginx
举报原因:
原因补充:

(最多只允许输入30个字)