1、准备工作
选首先安装这几个软件:GCC,PCRE(Perl Compatible Regular Expression),zlib,OpenSSL。
Nginx是C写的,需要用GCC编译;Nginx的Rewrite和HTTP模块会用到PCRE;Nginx中的Gzip用到zlib;
用命令“# gcc”,查看gcc是否安装;如果出现“gcc: no input files”信息,说明已经安装好了。
否则,就需要用命令“# yum install gcc”,进行安装了!一路可能需要多次输入y,进行确认。
安装好后,可以再用命令“#gcc”测试,或者用命令“# gcc -v”查看其版本号。
同样方法,用如下命令安装PCRE,zlib,OpenSSL(其中devel,是develop开发包的意思):

  1. # yum install -y pcre pcre-devel
  2. # yum install -y zlib zlib-devel
  3. # yum install -y openssl openssl-devel

2、下载并安装
创建目录(nginx-src)并进去;然后,从官方地址(http://nginx.org/)下载,解压,配置,编译,安装:

  1. # mkdir nginx-src && cd nginx-src
  2. # wget http://nginx.org/download/nginx-1.7.3.tar.gz
  3. # tar xzf nginx-1.7.3.tar.gz
  4. # cd nginx-1.7.3
  5. # ./configure
  6. # make
  7. # make install
  8. # whereis nginx
  9. nginx: /usr/local/nginx

默认的安装路径为:/usr/local/nginx;跳转到其目录下sbin路径下,便可以启动或停止它了。

  1. # ./nginx -h
  2. nginx version: nginx/1.7.3
  3. Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
  4. Options:
  5. -?,-h         : this help
  6. -v            : show version and exit
  7. -V            : show version and configure options then exit
  8. -t            : test configuration and exit
  9. -q            : suppress non-error messages during configuration testing
  10. -s signal     : send signal to a master process: stop, quit, reopen, reload
  11. -p prefix     : set prefix path (default: /usr/local/nginx/)
  12. -c filename   : set configuration file (default: conf/nginx.conf)
  13. -g directives : set global directives out of configuration file

启动:nginx

测试是否正常:在浏览器输入服务器所在主机IP(202.116.147.88:80)测试是否成功。如果80端口被apache占用,可视情况修改nginx端口号或apache端口号。

停止:nginx -s stop

3、添加到系统服务
使用命令“# vi /etc/init.d/nginx”,打开编辑器,输入如下内容:

  1. #!/bin/sh
  2. # chkconfig: 2345 85 15
  3. # Startup script for the nginx Web Server
  4. # description: nginx is a World Wide Web server.
  5. # It is used to serve HTML files and CGI.
  6. # processname: nginx
  7. # pidfile: /usr/local/nginx/logs/nginx.pid
  8. # config: /usr/local/nginx/conf/nginx.conf
  9. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  10. DESC="nginx deamon"
  11. NAME=nginx
  12. DAEMON=/usr/local/nginx/sbin/$NAME
  13. SCRIPTNAME=/etc/init.d/$NAME
  14. test -x $DAEMON || exit 0
  15. d_start(){
  16. $DAEMON || echo -n "already running"
  17. }
  18. d_stop(){
  19. $DAEMON -s quit || echo -n "not running"
  20. }
  21. d_reload(){
  22. $DAEMON -s reload || echo -n "can not reload"
  23. }
  24. case "$1" in
  25. start)
  26. echo -n "Starting $DESC: $NAME"
  27. d_start
  28. echo "."
  29. ;;
  30. stop)
  31. echo -n "Stopping $DESC: $NAME"
  32. d_stop
  33. echo "."
  34. ;;
  35. reload)
  36. echo -n "Reloading $DESC conf..."
  37. d_reload
  38. echo "reload ."
  39. ;;
  40. restart)
  41. echo -n "Restarting $DESC: $NAME"
  42. d_stop
  43. sleep 2
  44. d_start
  45. echo "."
  46. ;;
  47. *)
  48. echo "Usage: $ScRIPTNAME {start|stop|reload|restart}" >&2
  49. exit 3
  50. ;;
  51. esac
  52. exit 0

保存退出后,再使用下面的命令,使其可执行;然后,添加配置并查看。
可用chkconfig修改其值,也可用ntsysv工具改变是否自启动。

    1. # chmod +x /etc/init.d/nginx
    2. # chkconfig --add nginx
    3. # chkconfig nginx on/off
    4. # chkconfig --list nginx
    5. nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off

至此,nginx已经安装完成。

附pcre的源码安装方法:

PCRE(Perl Compatible Regular Expressions)是一个轻量级的Perl函数库,包括 perl 兼容的正则表达式库。它比Boost之类的正则表达式库小得多。PCRE十分易用,同时功能也很强大,性能超过了POSIX正则表达式库和一些经典的正则表达式库。

1. PCRE目前最新版本为8.36,可以点这里进行下载。

2. 使用tar -zxvf pcre-8.36.tar.gz进行解压。

3. 运行 chmod -R 777 /pcre-8.36 对当前文件夹授予全部读写权限。

4. 切换到/pcre-8.36目录下,运行 ./configure 进行pcre初始化配置,会在控制台打印出一大堆的输出信息。

5. 执行make操作,进行编译。

[root@server06 pcre-8.36]# make 
rm -f pcre_chartables.c 
ln -s ./pcre_chartables.c.dist pcre_chartables.c 
make  all-am 
make[1]: Entering directory `/opt/nginx/pcre-8.36' 
  CC      libpcre_la-pcre_byte_order.lo 
  CC      libpcre_la-pcre_compile.lo 
  CC      libpcre_la-pcre_config.lo 
  CC      libpcre_la-pcre_dfa_exec.lo 
  CC      libpcre_la-pcre_exec.lo 
  CC      libpcre_la-pcre_fullinfo.lo 
  CC      libpcre_la-pcre_get.lo 
  CC      libpcre_la-pcre_globals.lo 
  CC      libpcre_la-pcre_jit_compile.lo 
  CC      libpcre_la-pcre_maketables.lo 
  CC      libpcre_la-pcre_newline.lo 
  CC      libpcre_la-pcre_ord2utf8.lo 
  CC      libpcre_la-pcre_refcount.lo 
  CC      libpcre_la-pcre_string_utils.lo 
  CC      libpcre_la-pcre_study.lo 
  CC      libpcre_la-pcre_tables.lo 
  CC      libpcre_la-pcre_ucd.lo 
  CC      libpcre_la-pcre_valid_utf8.lo 
  CC      libpcre_la-pcre_version.lo 
  CC      libpcre_la-pcre_xclass.lo 
  CC      libpcre_la-pcre_chartables.lo 
  CCLD    libpcre.la 
  CC      libpcreposix_la-pcreposix.lo 
  CCLD    libpcreposix.la 
  CXX      libpcrecpp_la-pcrecpp.lo 
  CXX      libpcrecpp_la-pcre_scanner.lo 
  CXX      libpcrecpp_la-pcre_stringpiece.lo 
  CXXLD    libpcrecpp.la 
  CC      pcretest-pcretest.o 
  CC      pcretest-pcre_printint.o 
  CCLD    pcretest 
  CC      pcregrep-pcregrep.o 
  CCLD    pcregrep 
  CXX      pcrecpp_unittest-pcrecpp_unittest.o 
  CXXLD    pcrecpp_unittest 
  CXX      pcre_scanner_unittest-pcre_scanner_unittest.o 
  CXXLD    pcre_scanner_unittest 
  CXX      pcre_stringpiece_unittest-pcre_stringpiece_unittest.o 
  CXXLD    pcre_stringpiece_unittest 
make[1]: Leaving directory `/opt/nginx/pcre-8.36'

6. 运行 [root@server06 pcre-8.36]# make install,进行安装,至此PCRE安装完成。

[root@server06 pcre-8.36]# make install

linux应用之nginx的源码安装及配置(centos)的更多相关文章

  1. nginx在Centos7.5下源码安装和配置

    安装nginx 安装nginx依赖包 yum install -y pcre-devel zlib-devel openssl-devel wget gcc tree vim 进入目录/root/se ...

  2. linux下MySQL 5.6源码安装

    linux下MySQL 5.6源码安装 1.下载:当前mysql版本到了5.6.20 http://dev.mysql.com/downloads/mysql 选择Source Code 2.必要软件 ...

  3. Nginx unit 源码安装初体验

    Nginx unit 源码安装初体验 上次介绍了从yum的安装方法(https://www.cnblogs.com/wang-li/p/9684040.html),这次将介绍源码安装,目前最新版为1. ...

  4. 关于nginx的源码安装方式

    Nginx(engine x)是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器, 也是一个 IMAP/POP3/SMTP 代理服务器.在高连接并发的情况下, ...

  5. 编译nginx的源码安装subs_filter模块

    使用nginx的反向代理功能搭建nuget镜像服务器时,需要针对官方nuget服务器的响应内容进行字符串替换,比如将www.nuget.org替换为镜像服务器的主机名,将https://替换为http ...

  6. nginx 的源码安装

    安装nginx之前要做的准备工作有:安装如下库 (1)gzip模块需要 zlib 库 (2)rewrite模块需要 pcre 库 (3)ssl 功能需要openssl库 还有一种简单的方法就是 yum ...

  7. NFS, web,负载均衡,Nginx yum 源码安装

    作业一:nginx服务1.二进制安装nginx 2.作为web服务修改配置文件 3.让配置生效,验证配置  [root@localhost ~]# systemctl stop firewalld.s ...

  8. nginx源码安装教程(CentOS)

    1.说明 官方源码安装说明:http://nginx.org/en/docs/configure.html 源码包下载地址:http://nginx.org/en/download.html 版本说明 ...

  9. 【程序包管理】Linux软件管理之src源码安装编译

    在很多时候我们需要自定义软件的特性,这时就需要用到源码安装.那么,网上有很多编译源码的工具,那么,我们怎么知道别人使用的是什么工具呢.其实我也不知道(*^▽^*). 那么本篇博客主要是写C代码的源码安 ...

随机推荐

  1. Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental……

    Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to th ...

  2. Linux中运行c程序,与系统打交道

    例一:system系统调用是为了方便调用外部程序,执行完毕后返回调用进程. #include <stdio.h> #include <stdlib.h> main() { pr ...

  3. js:argument

    引用:http://www.cnblogs.com/lwbqqyumidi/archive/2012/12/03/2799833.html    http://www.cnblogs.com/Fskj ...

  4. ubuntu 下开源安装

    常用开源库安装: 0.安装g++: sudo apt-get install g++ 1.首先不可或缺的就是编译器与基本的函式库: sudo apt-get install build-essenti ...

  5. windows下rsync部署安装

    windows下rsync部署安装 2012-06-05 12:06:13|  分类: 系统 |  标签:rsync  windows   |字号 订阅   rsync在windows与windows ...

  6. LeetCode 之 Valid Palindrome(字符串)

    [问题描写叙述] Given a string, determine if it is a palindrome, considering only alphanumeric characters a ...

  7. Django之tag的使用

    settings.py: #安装 pip install django-taggit INSTALLED_APPS = [ 'myblog', 'taggit', 'django.contrib.ad ...

  8. HDFS源码分析EditLog之获取编辑日志输入流

    在<HDFS源码分析之EditLogTailer>一文中,我们详细了解了编辑日志跟踪器EditLogTailer的实现,介绍了其内部编辑日志追踪线程EditLogTailerThread的 ...

  9. 图像处理之log---log算子

    在图像中,边缘可以看做是位于一阶导数较大的像素处,因此,我们可以求图像的一阶导数来确定图像的边缘,像sobel算子等一系列算子都是基于这个思想的. 但是这存在几个问题:1. 噪声的影响,在噪声点处一阶 ...

  10. ASP.NET MVC 相关的社群与讨论区

    ASP.NET MVC 官方论坛  http://forums.asp.net/1146.aspx 台湾微软MSDN论坛 --- ASP.NET 与 AJAX(ASP.NET AND AJAX)讨论区 ...