1.安装前环境准备
安装make:
# yum -y install gcc automake autoconf libtool make
安装g++:
# yum install gcc gcc-c++

2.一般都需要先装pcre, zlib,前者为了重写rewrite,后者为了gzip压缩

安装pcre
下载地址: http://www.pcre.org/
# tar -xvf pcre-8.36.tar.gz
# cd pcre-8.36
# ./configure --prefix=/usr/local/pcre
# make
# make install

安装zlib
下载地址: http://www.zlib.net/
# cd /usr/local/src
# tar -xvf zlib-1.2.8.tar.gz
# cd zlib-1.2.8
# ./configure --prefix=/usr/local/zlib
# make
# make install

安装ssl(某些vps默认没装ssl)
# cd /usr/local/src
# wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
# tar -zxvf openssl-1.0.1c.tar.gz

3.安装Nginx
# groupadd vc_php_grp
# useradd -g vc_php_grp vc_php_usr -s /bin/nologin

  1. ./configure --prefix=/usr/local/nginx \
  2. --with-http_stub_status_module \
  3. --user=vc_php_usr \
  4. --group=vc_php_grp \
  5. --with-http_gzip_static_module \
  6. --with-zlib=/usr/local/src/zlib-1.2. \
  7. --with-pcre=/usr/local/src/pcre-8.36 \
  8. --with-openssl=/usr/local/src/openssl-1.0.1c
  1. Configuration summary
  2. + using PCRE library: /usr/local/src/pcre-8.36
  3. + using OpenSSL library: /usr/local/src/openssl-1.0.1c
  4. + using builtin md5 code
  5. + sha1 library is not found
  6. + using zlib library: /usr/local/src/zlib-1.2.
  7.  
  8. nginx path prefix: "/usr/local/nginx"
  9. nginx binary file: "/usr/local/nginx/sbin/nginx"
  10. nginx configuration prefix: "/usr/local/nginx/conf"
  11. nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  12. nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  13. nginx error log file: "/usr/local/nginx/logs/error.log"
  14. nginx http access log file: "/usr/local/nginx/logs/access.log"
  15. nginx http client request body temporary files: "client_body_temp"
  16. nginx http proxy temporary files: "proxy_temp"
  17. nginx http fastcgi temporary files: "fastcgi_temp"
  18. nginx http uwsgi temporary files: "uwsgi_temp"
  19. nginx http scgi temporary files: "scgi_temp"

注意:
--with-openssl=/usr/local/src/openssl-1.0.1c
--with-zlib=/usr/local/src/zlib-1.2.8
--with-pcre=/usr/local/src/pcre-8.36
指向的是源码包解压的路径,而不是安装的路径,否则会报错

4.启动nginx

/usr/local/nginx/sbin/nginx

5.设置开机重启

  1. vi /etc/init.d/nginx (输入下面的代码)
  2. #!/bin/bash
  3. # nginx Startup script for the Nginx HTTP Server
  4. # it is v.0.0. version.
  5. # chkconfig: -
  6. # description: Nginx is a high-performance web and proxy server.
  7. # It has a lot of features, but it's not for everyone.
  8. # processname: nginx
  9. # pidfile: /var/run/nginx.pid
  10. # config: /usr/local/nginx/conf/nginx.conf
  11. nginxd=/usr/local/nginx/sbin/nginx
  12. nginx_config=/usr/local/nginx/conf/nginx.conf
  13. nginx_pid=/usr/local/nginx/logs/nginx.pid
  14. RETVAL=
  15. prog="nginx"
  16. # Source function library.
  17. . /etc/rc.d/init.d/functions
  18. # Source networking configuration.
  19. . /etc/sysconfig/network
  20. # Check that networking is up.
  21. [ ${NETWORKING} = "no" ] && exit
  22. [ -x $nginxd ] || exit
  23. # Start nginx daemons functions.
  24. start() {
  25. if [ -e $nginx_pid ];then
  26. echo "nginx already running...."
  27. exit
  28. fi
  29. echo -n $"Starting $prog: "
  30. daemon $nginxd -c ${nginx_config}
  31. RETVAL=$?
  32. echo
  33. [ $RETVAL = ] && touch /var/lock/subsys/nginx
  34. return $RETVAL
  35. }
  36. # Stop nginx daemons functions.
  37. stop() {
  38. echo -n $"Stopping $prog: "
  39. killproc $nginxd
  40. RETVAL=$?
  41. echo
  42. [ $RETVAL = ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
  43. }
  44. # reload nginx service functions.
  45. reload() {
  46. echo -n $"Reloading $prog: "
  47. #kill -HUP `cat ${nginx_pid}`
  48. killproc $nginxd -HUP
  49. RETVAL=$?
  50. echo
  51. }
  52. # See how we were called.
  53. case "$1" in
  54. start)
  55. start
  56. ;;
  57. stop)
  58. stop
  59. ;;
  60. reload)
  61. reload
  62. ;;
  63. restart)
  64. stop
  65. start
  66. ;;
  67. status)
  68. status $prog
  69. RETVAL=$?
  70. ;;
  71. *)
  72. echo $"Usage: $prog {start|stop|restart|reload|status|help}"
  73. exit
  74. esac
  75. exit $RETVAL

# chmod 775 /etc/init.d/nginx #赋予文件执行权限
# chkconfig nginx on #设置开机启动
# /etc/init.d/nginx restart #重启

在浏览器中打开服务器IP地址,测试Nginx安装是否成功。

如果你需要处理php脚本的话,还需要安装php-fpm

linux 源码安装 Nginx的更多相关文章

  1. linux源码安装nginx

    任务目标:源码安装nginx,作为web服务修改配置文件,让配置生效,验证配置 首先要去官网nginx.org下载一个tar包: tar xvf 解包 进入到解包出来的目录,对configure进行配 ...

  2. 1.linux源码安装nginx

    从官网下载nginx.tar.gz源码包 拷贝至Linux系统下进行解压 tar -zxvf nginx.tar.gz 进入解压后的目录,需要./configure,此步骤会报多个错,比如没有安装gc ...

  3. Linux 源码安装nginx

    编译参数详解:https://www.cnblogs.com/houyongchong/p/compileArgs.html 配置参数详解:https://www.cnblogs.com/houyon ...

  4. Linux之源码安装nginx,并按照作业一描述的那样去测试使用

    作业五:源码安装nginx,并按照作业一描述的那样去测试使用 [root@localhost nginx]# yum install gcc-* glibc-* openssl openssl-dev ...

  5. 源码安装nginx以及平滑升级

                                                           源码安装nginx以及平滑升级                               ...

  6. Linux源码安装JDK1.8

    Linux源码安装Java 1.到官网下载 jdk-8u131-linux-x64.tar.gz 官网地址:http://www.oracle.com/technetwork/java/javase/ ...

  7. 源码安装Nginx以及用systemctl管理

    一.源码安装Nginx: 先安装gcc编译器(安装过的可以忽略) [root@localhost ~]# yum -y install gcc gcc-c++ wget 进入src目录 [root@l ...

  8. mysql-5.5 for linux源码安装

    mysql-5.5 for linux源码安装 1.使用Yum安装依赖软件包 # yum install -y gcc gcc-c++ gcc-g77 autoconf automake bison  ...

  9. 工作笔记-- 源码安装nginx

    源码安装nginx 1.安装nginx的依赖包 [root@localhost ~]# yum -y install gcc gcc-c++ openssl openssl-devel pcre pc ...

随机推荐

  1. 简化delegate写法

    标准的写法 空 简化后的宏 /**************************************************************/ // delegate 托付 /* #de ...

  2. php 将网页执行的输出写入到本地文件中

    php -f /var/www/html/default/script/lol_score_calculate/calculate.php >>score_calcutelate.log

  3. UIView独占响应事件

    exclusiveTouch A Boolean value that indicates whether the receiver handles touch events exclusively. ...

  4. SQLAlchemy如何给列和表添加注释comment?

    1.首先需要升级版本到1.2.x,我用的是1.2.14验证的,没有问题 2.看示例: class LoadResource(Base): """施压机资源."& ...

  5. go语言基础之运算符

    一.运算符分类 1.1 算术运算符 运算符 术语 示例 结果 + 加 10 + 5 15 - 减 10 - 5 5 * 乘 10 * 5 50 / 除 10 / 5 2 % 取模(取余) 10 % 3 ...

  6. hello--GAN

    GAN系列学习(1)——前生今世 DCGAN.WGAN.WGAN-GP.LSGAN.BEGAN原理总结及对比 [Learning Notes]变分自编码器(Variational Auto-Encod ...

  7. 【版本】API NDK 系统 分辨率 统计

    Android版本号 版本  API/NDK版本号  代号                        发布时间 7.1.1          25            Nougat      7 ...

  8. C#方法中的ref和out

    ref        通常我们向方法中传递的是值.方法获得的是这些值的一个拷贝,然后使用这些拷贝,当方法运行完毕后,这些拷贝将被丢弃,而原来的值不将受到影响.此外我们还有其他向方法传递参数的形式,引用 ...

  9. 使用nmonchart把.nmon文件转换成html

    转载:https://blog.csdn.net/zd470015321/article/details/68923280 我的环境 :centos6.6 下载地址 nmon: http://nmon ...

  10. 【Python】爬取理想论坛单帖爬虫

    代码: # 单帖爬虫,用于爬取理想论坛帖子得到发帖人,发帖时间和回帖时间,url例子见main函数 from bs4 import BeautifulSoup import requests impo ...