Chinaunix首页 | 论坛 | 博客
  • 博客访问: 10919
  • 博文数量: 5
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 50
  • 用 户 组: 普通用户
  • 注册时间: 2016-01-07 14:37
个人简介

个人是个linux菜鸟 希望大家多多交流吧

文章分类
文章存档

2016年(5)

我的朋友
最近访客

分类: 系统运维

2016-06-21 16:49:51

nginx 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器,在高连接并发的情况下Nginx 是 Apache 服务器不错的替代品.其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好.目前中国大陆使用nginx网站用户有:新浪、网易、 腾讯

而且Nginx 启动特别容易,并且几乎可以做到 7*24 不间断运行,即使运行数个月也不需要重新启动。 你还能够不间断服务的情况下进行软件版本的升级。


下面是我自己总结一个安装nginx的文档  后期可能会有一些变动 



准备工作 下载nginx安装包
安装编译包
yum install gcc* lib* *c++* cmake make openssl* -y 


上传包nginx-1.6.2.tar.gz 到root


解包


-C 的参数是解压到 后面跟路径 

进入目录并查看

configure
文件是执行编译文件 开始编译

./configure --prefix=/usr/local/nginx \
--without-http_autoindex_module \
--without-http_geo_module \
--without-http_geo_module  \
--without-http_map_module \
--without-http_browser_module \ 
--with-http_stub_status_module  \
--with-http_realip_module \
--with-pcre 

具体的可以参数可以通过configure --help 进行查看 

提示我报错

说明没有缺少pcre包
安装


ok  我们继续 在编译一次

好 出现这些 说明nginx已经编译成功了  接下来 执行make && make install

没什么问题 就OK了

接下来 让我们进入到nginx的目录

conf 目录存放的是nginx的一些配置文件

html目录则存放的是nginx一些网页文件
logs存放的是nginx 的日志 与pid文件
sbin 存放的则是nginx启动文件

进入sbin目录 执行./nginx nginx就启动了
然后执行一下ps -ef | grep nginx  查看一下nginx进程是否启动


在通过浏览器访问一下看看能否访问
由于我这是测试服务器 所以将iptables关闭 selinux 也关闭了
方法
service iptables stop
setenforce 0



已经ok 到这里 nginx就是搭建完成了  可能有些人要问 每次进入nginx下的sbin目录去启动nginx会很麻烦
有没有什么能让nginx service中
答案是可以的
编写nginx启动脚本
vim /etc/rc.d/ini.d/nginx

点击(此处)折叠或打开

  1. #!/bin/sh
  2. #
  3. # nginx - this script starts and stops the nginx daemin
  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: /usr/local/nginx/conf/nginx.conf
  10. # pidfile: /usr/local/nginx/logs/nginx.pid

  11. # Source function library.
  12. . /etc/rc.d/init.d/functions

  13. # Source networking configuration.
  14. . /etc/sysconfig/network

  15. # Check that networking is up.
  16. [ "$NETWORKING" = "no" ] && exit 0

  17. nginx="/usr/local/nginx/sbin/nginx"
  18. prog=$(basename $nginx)

  19. NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"

  20. lockfile=/var/lock/subsys/nginx

  21. start() {
  22.     [ -x $nginx ] || exit 5
  23.     [ -f $NGINX_CONF_FILE ] || exit 6
  24.     echo -n $"Starting $prog: "
  25.     daemon $nginx -c $NGINX_CONF_FILE
  26.     retval=$?
  27.     echo
  28.     [ $retval -eq 0 ] && touch $lockfile
  29.     return $retval
  30. }

  31. stop() {
  32.     echo -n $"Stopping $prog: "
  33.     killproc $prog -QUIT
  34.     retval=$?
  35.     echo
  36.     [ $retval -eq 0 ] && rm -f $lockfile
  37.     return $retval
  38. }

  39. restart() {
  40.     configtest || return $?
  41.     stop
  42.     start
  43. }

  44. reload() {
  45.     configtest || return $?
  46.     echo -n $"Reloading $prog: "
  47.     killproc $nginx -HUP
  48.     RETVAL=$?
  49.     echo
  50. }

  51. force_reload() {
  52.     restart
  53. }

  54. configtest() {
  55.   $nginx -t -c $NGINX_CONF_FILE
  56. }

  57. rh_status() {
  58.     status $prog
  59. }

  60. rh_status_q() {
  61.     rh_status >/dev/null 2>&1
  62. }

  63. case "$1" in
  64.     start)
  65.         rh_status_q && exit 0
  66.         $1
  67.         ;;
  68.     stop)
  69.         rh_status_q || exit 0
  70.         $1
  71.         ;;
  72.     restart|configtest)
  73.         $1
  74.         ;;
  75.     reload)
  76.         rh_status_q || exit 7
  77.         $1
  78.         ;;
  79.     force-reload)
  80.         force_reload
  81.         ;;
  82.     status)
  83.         rh_status
  84.         ;;
  85.     condrestart|try-restart)
  86.         rh_status_q || exit 0
  87.             ;;
  88.     *)
  89.         echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  90.         exit 2
  91. esac
#脚本21行是你nginx执行文件路径 如果不对请修改
#脚本24行是你nginx.conf文件路径 如果不对请修改

然后保存 并赋予执行权限
chmod +x /etc/rc.d/init.d/nginx
测试脚本是否可用


最后将nginx服务添加到开机自启动

chkconfig --add nginx
chkconfig nginx on

好了 到这里 源码搭建nginx 服务器就ok了
阅读(596) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:linux下一键安装lamp脚本

给主人留下些什么吧!~~