资讯专栏INFORMATION COLUMN

源码编译nginx

meteor199 / 2107人阅读

摘要:修改成配置文件的路径。保存脚本文件后设置文件的执行权限加完这个之后,就可以使用对进行启动,重启等操作了。设置开机自动启动

参考链接 http://www.cnblogs.com/zhoulf... ;
1、系统环境 CentOS 6.8
2、安装软件nginx (nginx-1.12.2.tar.gz)
3、其他所需软件 openssl-1.1.0g.tar.gz pcre-8.41.tar.gz zlib-1.2.11.tar.gz

在安装以上软件前,需要确保系统安装了g++、gcc、gcc-c++!!!
在安装以上软件前,需要确保系统安装了g++、gcc、gcc-c++!!!
在安装以上软件前,需要确保系统安装了g++、gcc、gcc-c++!!!

</>复制代码

  1. yum -y install gcc g++
  2. yum -y install gcc-c++
1、安装openssl

(官网下载地址 http://www.openssl.org)

</>复制代码

  1. //进入安装目录
  2. cd /usr/local
  3. //下载版本
  4. wget https://www.openssl.org/source/openssl-1.1.0g.tar.gz
  5. //解压
  6. tar -zxvf openssl-1.1.0g.tar.gz
  7. //进入目录
  8. cd openssl-1.1.0g
  9. //配置
  10. ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl/conf
  11. //编译安装
  12. make && make install
2、安装pcre

(官网下载地址 http://www.pcre.org/)

</>复制代码

  1. //进入安装目录
  2. cd /usr/local
  3. //下载软件版本
  4. wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
  5. //解压
  6. tar -zxvf pcre-8.41.tat.gz
  7. //进入目录
  8. cd pcre-8.41
  9. //配置
  10. ./configure --prefix=/usr/local/pcre/
  11. //编译安装
  12. make && make install
3、安装zlib包

(官网下载地址 http://www.zlib.net/)

</>复制代码

  1. //进入安装目录
  2. cd /usr/local
  3. //下载版本
  4. wget https://downloads.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz
  5. //解压
  6. tar -zxvf zlib-1.2.11.tar.gz
  7. //进入zlib目录
  8. cd zlib-1.2.11
  9. //配置
  10. ./configure --prefix=/usr/local/zlib
  11. //编译安装
  12. make && make install
4、安装nginx

(官网下载地址 https://nginx.org/en/download...

</>复制代码

  1. //添加www用户和www用户组
  2. groupadd www
  3. useradd -g www www 添加用户www到www用户组
  4. //创建网站根目录
  5. mkdir -p /var/www/root/
  6. chmod 775 /var/www/root/
  7. //进入目录
  8. cd /usr/local
  9. //下载版本
  10. wget https://nginx.org/download/nginx-1.12.2.tar.gz
  11. //解压
  12. tar -zxvf nginx-1.12.2.tar.gz
  13. //进入nginx目录文件呀
  14. cd nginx-1.12.2
  15. //配置 (使用openssl、pcre、zlib的源码路径)
  16. ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_ssl_module --with-openssl=/usr/local/openssl-1.1.0g --with-pcre=/usr/local/pcre-8.41 --with-zlib=/usr/local/zlib-1.2.11 --with-http_stub_status_module --with-threads
  17. //安装编译
  18. make && make install
  19. //验证
  20. /usr/local/nginx/sbin/nginx -V
  21. //查询nginx主进程号
  22. ps -ef | grep nginx
  23. //设置软连接
  24. ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/nginx
5、设置开机自动启动nginx

参考链接 http://blog.csdn.net/u0138700...

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

</>复制代码

  1. vi /etc/init.d/nginx

//复制一下代码到 /etc/init.d/nginx

</>复制代码

  1. #!/bin/sh
  2. #
  3. # nginx - this script starts and stops the nginx daemon
  4. #
  5. # chkconfig: - 85 15
  6. # description: NGINX is an HTTP(S) server, HTTP(S) reverse
  7. # proxy and IMAP/POP3 proxy server
  8. # processname: nginx
  9. # config: /etc/nginx/nginx.conf
  10. # config: /etc/sysconfig/nginx
  11. # pidfile: /var/run/nginx.pid
  12. # Source function library.
  13. . /etc/rc.d/init.d/functions
  14. # Source networking configuration.
  15. . /etc/sysconfig/network
  16. # Check that networking is up.
  17. [ "$NETWORKING" = "no" ] && exit 0
  18. nginx="/usr/local/nginx/sbin/nginx"
  19. prog=$(basename $nginx)
  20. NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
  21. [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
  22. lockfile=/var/lock/subsys/nginx
  23. make_dirs() {
  24. # make required directories
  25. user=`$nginx -V 2>&1 | grep "configure arguments:" | sed "s/[^*]*--user=([^ ]*).*/1/g" -`
  26. if [ -z "`grep $user /etc/passwd`" ]; then
  27. useradd -M -s /bin/nologin $user
  28. fi
  29. options=`$nginx -V 2>&1 | grep "configure arguments:"`
  30. for opt in $options; do
  31. if [ `echo $opt | grep ".*-temp-path"` ]; then
  32. value=`echo $opt | cut -d "=" -f 2`
  33. if [ ! -d "$value" ]; then
  34. # echo "creating" $value
  35. mkdir -p $value && chown -R $user $value
  36. fi
  37. fi
  38. done
  39. }
  40. start() {
  41. [ -x $nginx ] || exit 5
  42. [ -f $NGINX_CONF_FILE ] || exit 6
  43. make_dirs
  44. echo -n $"Starting $prog: "
  45. daemon $nginx -c $NGINX_CONF_FILE
  46. retval=$?
  47. echo
  48. [ $retval -eq 0 ] && touch $lockfile
  49. return $retval
  50. }
  51. stop() {
  52. echo -n $"Stopping $prog: "
  53. killproc $prog -QUIT
  54. retval=$?
  55. echo
  56. [ $retval -eq 0 ] && rm -f $lockfile
  57. return $retval
  58. }
  59. restart() {
  60. configtest || return $?
  61. stop
  62. sleep 1
  63. start
  64. }
  65. reload() {
  66. configtest || return $?
  67. echo -n $"Reloading $prog: "
  68. killproc $nginx -HUP
  69. RETVAL=$?
  70. echo
  71. }
  72. force_reload() {
  73. restart
  74. }
  75. configtest() {
  76. $nginx -t -c $NGINX_CONF_FILE
  77. }
  78. rh_status() {
  79. status $prog
  80. }
  81. rh_status_q() {
  82. rh_status >/dev/null 2>&1
  83. }
  84. case "$1" in
  85. start)
  86. rh_status_q && exit 0
  87. $1
  88. ;;
  89. stop)
  90. rh_status_q || exit 0
  91. $1
  92. ;;
  93. restart|configtest)
  94. $1
  95. ;;
  96. reload)
  97. rh_status_q || exit 7
  98. $1
  99. ;;
  100. force-reload)
  101. force_reload
  102. ;;
  103. status)
  104. rh_status
  105. ;;
  106. condrestart|try-restart)
  107. rh_status_q || exit 0
  108. ;;
  109. *)
  110. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  111. exit 2
  112. esac

//修改自己nginx的位置 按照上面一步一步来安装已经已经配置好,复制直接可用,跳过此步

</>复制代码

  1. nginx="/usr/local/nginx/sbin/nginx" //修改成nginx执行程序的路径。
  2. NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" //修改成配置文件的路径。

//保存脚本文件后设置文件的执行权限:

</>复制代码

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

//加完这个之后,就可以使用service对nginx进行启动,重启等操作了。

</>复制代码

  1. /etc/init.d/nginx start
  2. /etc/init.d/nginx stop

//设置开机自动启动nginx

</>复制代码

  1. chkconfig nginx on

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/39921.html

相关文章

  • 全新centos系统下源码安装php+nginx

    摘要:安装完成后,可以随时更改的名称在配置文件中使用的指令。启用或禁用构建一个模块来允许服务器使用方法。如需要需要增加支持的文件数量设置附加的参数,将用于在链接期间。 前言 安装软件列表 nginx-1.13.9 php-7.2.3 操作系统 阿里云esc centos 7.4 64位 前提条件 yum install -y gcc gcc-c++ openssl openssl-de...

    dkzwm 评论0 收藏0
  • 全新centos系统下源码安装php+nginx

    摘要:安装完成后,可以随时更改的名称在配置文件中使用的指令。启用或禁用构建一个模块来允许服务器使用方法。如需要需要增加支持的文件数量设置附加的参数,将用于在链接期间。 前言 安装软件列表 nginx-1.13.9 php-7.2.3 操作系统 阿里云esc centos 7.4 64位 前提条件 yum install -y gcc gcc-c++ openssl openssl-de...

    honmaple 评论0 收藏0

发表评论

0条评论

meteor199

|高级讲师

TA的文章

阅读更多
最新活动
阅读需要支付1元查看
<