Nginx实战基础篇一 源码包编译安装部署web服务器

版权声明:

本文遵循“署名非商业性使用相同方式共享 2.5 中国大陆”协议

您可以自由复制、发行、展览、表演、放映、广播或通过信息网络传播本作品

您可以根据本作品演义自己的作品

您必须按照作者或者许可人指定的方式对作品进行署名。

您不得将本作品用于商业目的。

如果您改变、转换本作品或者以本作品为基础进行创作,您只能采用与本协议相同的许可协议发布基于本作品的演绎作品。

对任何再使用或者发行,您都必须向他人清楚地展示本作品使用的许可协议条款。

如果得到著作权人的许可,您可以不受任何这些条件的限制。

Designed by 小诺(www.rsyslog.org  dreamfire.blog.51cto.com

实验步骤:

一、安装nginx必须的依赖包

  1. [root@rhel6u3-7 ~]# yum -y install gcc openssl-devel pcre-devel zlib-devel  //yum创建过程略,安装略

二、安装编译nginx,目前系统测试环境为rhel6.3  软件版本为nginx-1.27

  1. [root@rhel6u3-7 ~]# useradd nginx -s /sbin/nologin //给nginx服务器创建后台进程管理用户
  2. [root@rhel6u3-7 ~]# tar zxvf nginx-1.2.7.tar.gz  //解压缩
  3. [root@rhel6u3-7 ~]# cd nginx-1.2.7
  4. [root@rhel6u3-7 nginx-1.2.7]# ./configure --user=nginx --group=nginx --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-http_ssl_module
  5. // --user=nginx –group=nginx 设置允许nginx允许的用户和组为nginx
  6. // --prefix=/usr/local/nginx/  设置nginx安装路径
  7. // --with-http_stub_status_module 安装允许状态模块
  8. // --with-http_ssl_module 安装ssl模块
  9. //更多参数请参看 ./configure --help
  10. ……  //安装显示略,如果配置正确,最后会显示以下信息。
  11. Configuration summary
  12. + using system PCRE library
  13. + using system OpenSSL library
  14. + md5: using OpenSSL library
  15. + sha1: using OpenSSL library
  16. + using system zlib library
  17. nginx path prefix: "/usr/local/nginx/"
  18. nginx binary file: "/usr/local/nginx//sbin/nginx"
  19. nginx configuration prefix: "/usr/local/nginx//conf"
  20. nginx configuration file: "/usr/local/nginx//conf/nginx.conf"
  21. nginx pid file: "/usr/local/nginx//logs/nginx.pid"
  22. nginx error log file: "/usr/local/nginx//logs/error.log"
  23. nginx http access log file: "/usr/local/nginx//logs/access.log"
  24. nginx http client request body temporary files: "client_body_temp"
  25. nginx http proxy temporary files: "proxy_temp"
  26. nginx http fastcgi temporary files: "fastcgi_temp"
  27. nginx http uwsgi temporary files: "uwsgi_temp"
  28. nginx http scgi temporary files: "scgi_temp"
  29. [root@rhel6u3-7 ~]# /usr/local/nginx/sbin/nginx  –V  //安装完成后查看Nginx的相关环境配置信息是否正确
  30. nginx version: nginx/1.2.7
  31. built by gcc 4.4.6 20120305 (Red Hat 4.4.6-4) (GCC)
  32. TLS SNI support enabled
  33. configure arguments: --user=nginx --group=nginx --prefix=/usr/local/nginx/ --with-http_stub_status_module --with-http_ssl_module
  34. [root@rhel6u3-7 ~]#
  35. [root@rhel6u3-7 nginx-1.2.7]# make & make install   //编译安装过程略

三、通过nginx自身脚本机器nginx服务器,并通过各种命令查看是否启动成功

  1. [root@rhel6u3-7 ~]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf   // -c指向nginx主配置文件
  2. [root@rhel6u3-7 ~]# lsof -i :80  //查看nginx进程号及运行情况
  3. COMMAND  PID  USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
  4. nginx   4080  root    6u  IPv4  21467      0t0  TCP *:http (LISTEN)
  5. nginx   4081 nginx    6u  IPv4  21467      0t0  TCP *:http (LISTEN)
  6. [root@rhel6u3-7 ~]# ps -ef | grep nginx  //查看nginx进程号及运行情况
  7. root      4080     1  0 22:24 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
  8. nginx     4081  4080  0 22:24 ?        00:00:00 nginx: worker process
  9. root      4088  1433  0 22:27 pts/0    00:00:00 grep nginx
  10. [root@rhel6u3-7 ~]# netstat -nltp | grep 80  //查看nginx进程监听端口
  11. tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      4080/nginx

,测试nginx配置的默认web服务器是否能正常运行

通过linux自带命令links 测试

  1. [root@rhel6u3-7 ~]# links 127.0.0.1  //出现 welcome to nginx!说明nginx服务启动成功

通过windows服务器IE浏览器测试

扩展知识:

1、设置nginx开机自动启动,将nginx启动命令添加到/etc/rc.local

  1. [root@rhel6u3-7 ~]# echo "/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf" >> /etc/rc.local
  2. [root@rhel6u3-7 ~]# cat /etc/rc.local | grep nginx
  3. /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

2、通过设置System V 脚本,使用server命令启动nginx服务

  1. [root@rhel6u3-7 init.d]# vim  nginx  //在/etc/init.d/下创建nginx启动脚本文件
  2. #!/bin/sh
  3. #
  4. # nginx - this script starts and stops the nginx daemon
  5. #
  6. # chkconfig: - 85 15
  7. # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
  8. #   proxy and IMAP/POP3 proxy server
  9. # processname: nginx
  10. # config: /etc/nginx/nginx.conf
  11. # config: /etc/sysconfig/nginx
  12. # pidfile: /var/run/nginx.pid
  13. # Source function library.
  14. . /etc/rc.d/init.d/functions
  15. # Source networking configuration.
  16. . /etc/sysconfig/network
  17. # Check that networking is up.
  18. [ "$NETWORKING" = "no" ] && exit 0
  19. nginx="/usr/local/nginx/sbin/nginx"
  20. prog=$(basename $nginx)
  21. NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
  22. [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
  23. lockfile=/var/lock/subsys/nginx
  24. start() {
  25. [ -x $nginx ] || exit 5
  26. [ -f $NGINX_CONF_FILE ] || exit 6
  27. echo -n $"Starting $prog: "
  28. daemon $nginx -c $NGINX_CONF_FILE
  29. retval=$?
  30. echo
  31. [ $retval -eq 0 ] && touch $lockfile
  32. return $retval
  33. }
  34. stop() {
  35. echo -n $"Stopping $prog: "
  36. killproc $prog -QUIT
  37. retval=$?
  38. echo
  39. [ $retval -eq 0 ] && rm -f $lockfile
  40. return $retval
  41. killall -9 nginx
  42. }
  43. restart() {
  44. configtest || return $?
  45. stop
  46. sleep 1
  47. start
  48. }
  49. reload() {
  50. configtest || return $?
  51. echo -n $"Reloading $prog: "
  52. killproc $nginx -HUP
  53. RETVAL=$?
  54. echo
  55. }
  56. force_reload() {
  57. restart
  58. }
  59. configtest() {
  60. $nginx -t -c $NGINX_CONF_FILE
  61. }
  62. rh_status() {
  63. status $prog
  64. }
  65. rh_status_q() {
  66. rh_status >/dev/null 2>&1
  67. }
  68. case "$1" in
  69. start)
  70. rh_status_q && exit 0
  71. $1
  72. ;;
  73. stop)
  74. rh_status_q || exit 0
  75. $1
  76. ;;
  77. restart|configtest)
  78. $1
  79. ;;
  80. reload)
  81. rh_status_q || exit 7
  82. $1
  83. ;;
  84. force-reload)
  85. force_reload
  86. ;;
  87. status)
  88. rh_status
  89. ;;
  90. condrestart|try-restart)
  91. rh_status_q || exit 0
  92. ;;
  93. *)
  94. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  95. exit 2
  96. esac
  1. [root@rhel6u3-7 init.d]# chmod 755 nginx   //修改脚本文件nginx的权限
  2. [root@rhel6u3-7 init.d]# chkconfig --add nginx  //将脚本文件加入chkconfig中
  3. [root@rhel6u3-7 init.d]# chkconfig --level 35 nginx on  //设置nginx开机在3和5级别自动启动
  4. [root@rhel6u3-7 init.d]# chkconfig --list | grep nginx
  5. nginx           0:off   1:off   2:off   3:on    4:off   5:on    6:off

Nginx实战基础篇PDF高清下载系列:

Nginx实战基础篇一:源码包编译安装部署web服务器  

http://down.51cto.com/data/688744

Nginx实战基础篇二:Nginx主配置文件参数详解

http://down.51cto.com/data/688835

Nginx实战基础篇三:Nginx上虚拟主机的实现过程

http://down.51cto.com/data/688836

Nginx实战基础篇四:通过https方式安全访问web服务器

http://down.51cto.com/data/689197

Nginx实战基础篇五:Nginx上实现用户名密码认证访问

http://down.51cto.com/data/694934

Nginx实战基础篇六:通过源码包编译安装部署LNMP搭建Discuz论坛

http://down.51cto.com/data/694932

测试nginx脚本文件是否能够正常使用

  1. [root@rhel6u3-7 init.d]# /etc/init.d/nginx restart  //重新启动
  2. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  3. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
  4. Stopping nginx:                                            [  OK  ]
  5. Starting nginx:                                            [  OK  ]
  6. [root@rhel6u3-7 init.d]# /etc/init.d/nginx reload  //不间断服务平滑重启
  7. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  8. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
  9. Reloading nginx:                                           [  OK  ]
  10. [root@rhel6u3-7 ~]# cat /usr/local/nginx/logs/nginx.pid  //存储了nginx运行的进程号
  11. 15799
  12. [root@rhel6u3-7 ~]# kill -HUP `cat /usr/local/nginx/logs/nginx.pid` //不间断服务重新启动nginx
  13. [root@rhel6u3-7 init.d]# /etc/init.d/nginx stop
  14. Stopping nginx:                                            [  OK  ]
  15. [root@rhel6u3-7 init.d]# killall -9 nginx  //结束nginx的全部经常
  1. [root@rhel6u3-7 html]# pwd  //安装nginx完成后,默认网站的路径
  2. /usr/local/nginx/html
  3. [root@rhel6u3-7 html]# ll    //可以查看到默认网站为index.html,内容为以上测试内容。
  4. total 8
  5. -rw-r--r-- 1 root root 537 Feb 25 22:21 50x.html
  6. -rw-r--r-- 1 root root 612 Feb 25 22:21 index.html

Nginx实战基础篇一 源码包编译安装部署web服务器相关推荐

  1. Nginx实战基础篇六 通过源码包编译安装部署LNMP搭建Discuz论坛

    Nginx实战基础篇六 通过源码包编译安装部署LNMP搭建Discuz论坛 版权声明: 本文遵循"署名非商业性使用相同方式共享 2.5 中国大陆"协议 您可以自由复制.发行.展览. ...

  2. 如何在源码包编译安装的 LEMP 环境下开启 OpenSSL 功能

    如何在源码包编译安装的 LEMP 环境下开启 OpenSSL 功能 Hello,大家好!我是--邪恶君子! 今天,给大家分享一下解决源码包编译安装 LEMP 环境下开启 OpenSSL 功能问题的过程 ...

  3. zabbix 3.2.2 server端(源码包)安装部署 (一)【转】

    环境准备: 操作系统 CentOS 6.8 2.6.32-642.11.1.el6.x86_64 zabbix server 172.16.10.150 zabbix agent 172.16.10. ...

  4. 编译 php mysql 依赖包_MySQL 5.5.15源码包编译安装

    mysql果然是不愧是目前最火的数据库,自从mysql5.5.8之后,mysql的源码包编译安装都要用到cmake来进行编译了,编译的过程没有本质 mysql果然是不愧是目前最火的数据库,自从mysq ...

  5. 从源码开始编译一个带有WEB服务器功能的小型LINUX(下)

    上接:从源码开始编译一个带有WEB服务器功能的小型LINUX(上) 七.为新构建的ToyLinux启用虚拟控制台 这个可以通过宿主机来实现,也可以直接启动刚构建成功的小Linux进行配置.我们这里采用 ...

  6. RedHat6.4系统下LAMP环境的搭建---(源码包编译安装)---v1.0

    一:配置本地yum源 :--目录 作者:李文轩 座右铭:一个愿意为理想奋斗终生的人! 联系QQ:838997384 网站地址:www.74cto.com 说明:本篇安装的系统版本RedHat6.4(6 ...

  7. MySQL源码包编译安装

    +++++++++++++++++++++++++++++++++++++++++++ 标题:MySQL数据库实例部署 时间:2019年5月2日 内容:MySQL源码包进行编译,然后部署MySQL单实 ...

  8. nginx源码包编译安装

    1.到官方站点卸载nginx-1.6.3版本的源码包 http://nginx.org/en/download.html http://nginx.org 2.安装依赖包和编译工具 yum -y in ...

  9. CentOS 7下nginx源码包编译安装

    一.下载 nginx 源码包 这里我们选择稳定版: 把下载完的nginx-1.13.12.tar.gz包上传到服务器上 或者可以在服务器上使用终端下载: [root@localhost ~]# cd ...

最新文章

  1. HTTP请求报文和HTTP响应报文(转)
  2. iPhone UITextField-更改占位符文本颜色
  3. 面试:说说你对“零拷贝”的理解?
  4. 联想n308 android 一体机,附文:N308设计回顾_联想 N308_一体电脑评测-中关村在线...
  5. python安装MySQLdb包遇到的坑:EnvironmentError: mysql_config not found
  6. Spring注解开发-属性依赖注入指定名称的bean
  7. Linux进程全解1——程序的开始、结束
  8. 使用TensorFlow,GPU和Docker容器进行深度学习
  9. Plasm金丝雀网络Shiden Network即将启动
  10. Axure电商服务小程序交互原型模板、电商小程序、拼团特惠、积分兑换、LBS电商小程序、活动、订单、会员、购物车、签到、钱包充值、拼团拼单、优惠券、电商原型、rp源文件、Axure原型、移动端电商系统
  11. Noise,Error,wighted pocket Algorithm
  12. DB2 数据库密码过期
  13. GitHub 和 gitlab 的使用
  14. 使用定积分计算三角形面积
  15. 添加w3c验证图片到网站
  16. 快速接入百度大脑身份证识别
  17. Elasticsearch自定义客户端(TransportClient)资源池
  18. ZZULIOJ.1102: 火车票退票费计算(函数专题)
  19. 20-《电子入门趣谈》第四章_自己制作电路板-4.1面包板的介绍和经典案例使用教程
  20. 我的人工智能之旅——偏斜类问题

热门文章

  1. Windows Phone开发(28):隔离存储B 转:http://blog.csdn.net/tcjiaan/article/details/7436959...
  2. Nobody can go back and start a new beginning, but anyone can start now and make a new ending.
  3. 一种真正意义上的Session劫持
  4. java jdbc实验,实验八 Java-JDBC编程
  5. Nodejs学习笔记(七)——接口API
  6. 确定不进来看看?分享一个插件,让敲代码不再枯燥,activate-power-mode
  7. linux init 参数,Objective-C中实现覆写init函数以及在初始化时添加参数
  8. ReactiveX流式编程—从xstream讲起
  9. 自动化运维工具Ansible连续剧之--介绍安装与连接
  10. Java™ 教程(常见问题及其解决方案)