手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

RHEL5上配置LNMP环境安装shopex

[日期:2013-03-25] 来源:51cto  作者:loveganen [字体:大 中 小]

二、安装Nginx

1.首先添加用户nginx,实现以之运行nginx服务进程。

  1. # groupadd -r nginx
  2. # useradd -r -g nginx nginx

2.解压进行编译安装

  1. # cd /usr/local/src
  2. # tar zxvf nginx-1.2.7.tar.gz
  3. # cd nginx-1.2.7
  4. # ./configure \
  5. --prefix=/usr \
  6. --sbin-path=/usr/sbin/nginx \
  7. --conf-path=/etc/nginx/nginx.conf \
  8. --error-log-path=/var/log/nginx/error.log \
  9. --http-log-path=/var/log/nginx/access.log \
  10. --pid-path=/var/run/nginx/nginx.pid \
  11. --lock-path=/var/lock/nginx.lock \
  12. --user=nginx \
  13. --group=nginx \
  14. --with-http_ssl_module \
  15. --with-http_flv_module \
  16. --with-http_stub_status_module \
  17. --with-http_gzip_static_module \
  18. --http-client-body-temp-path=/var/tmp/nginx/client/ \
  19. --http-proxy-temp-path=/var/tmp/nginx/proxy/ \
  20. --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
  21. --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
  22. --http-scgi-temp-path=/var/tmp/nginx/scgi \
  23. --with-pcre
  24. # make && make install

 

说明:如果想使用nginx的perl模块,可以通过为configure脚本添加--with-http_perl_module选项来实现,但目前此模块仍处于实验性使用阶段,可能会在运行中出现意外,因此,其实现方式这里不再介绍。如果想使用基于nginx的cgi功能,也可以基于FCGI来实现,具体实现方法请参照相关文档

3.为nginx提供SysV init脚本。

新建文件/etc/rc.d/init.d/nginx,内容如下:

  1. # vim /etc/rc.d/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/sbin/nginx"
  20. prog=$(basename $nginx)
  21. NGINX_CONF_FILE="/etc/nginx/nginx.conf"
  22. [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
  23. lockfile=/var/lock/subsys/nginx
  24. make_dirs() {
  25. # make required directories
  26. user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
  27. options=`$nginx -V 2>&1 | grep 'configure arguments:'`
  28. for opt in $options; do
  29. if [ `echo $opt | grep '.*-temp-path'` ]; then
  30. value=`echo $opt | cut -d "=" -f 2`
  31. if [ ! -d "$value" ]; then
  32. # echo "creating" $value
  33. mkdir -p $value && chown -R $user $value
  34. fi
  35. fi
  36. done
  37. }
  38. start() {
  39. [ -x $nginx ] || exit 5
  40. [ -f $NGINX_CONF_FILE ] || exit 6
  41. make_dirs
  42. echo -n $"Starting $prog: "
  43. daemon $nginx -c $NGINX_CONF_FILE
  44. retval=$?
  45. echo
  46. [ $retval -eq 0 ] && touch $lockfile
  47. return $retval
  48. }
  49. stop() {
  50. echo -n $"Stopping $prog: "
  51. killproc $prog -QUIT
  52. retval=$?
  53. echo
  54. [ $retval -eq 0 ] && rm -f $lockfile
  55. return $retval
  56. }
  57. restart() {
  58. configtest || return $?
  59. stop
  60. sleep 1
  61. start
  62. }
  63. reload() {
  64. configtest || return $?
  65. echo -n $"Reloading $prog: "
  66. killproc $nginx -HUP
  67. RETVAL=$?
  68. echo
  69. }
  70. force_reload() {
  71. restart
  72. }
  73. configtest() {
  74. $nginx -t -c $NGINX_CONF_FILE
  75. }
  76. rh_status() {
  77. status $prog
  78. }
  79. rh_status_q() {
  80. rh_status >/dev/null 2>&1
  81. }
  82. case "$1" in
  83. start)
  84. rh_status_q && exit 0
  85. $1
  86. ;;
  87. stop)
  88. rh_status_q || exit 0
  89. $1
  90. ;;
  91. restart|configtest)
  92. $1
  93. ;;
  94. reload)
  95. rh_status_q || exit 7
  96. $1
  97. ;;
  98. force-reload)
  99. force_reload
  100. ;;
  101. status)
  102. rh_status
  103. ;;
  104. condrestart|try-restart)
  105. rh_status_q || exit 0
  106. ;;
  107. *)
  108. echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  109. exit 2
  110. esac

而后为此脚本赋予执行权限

  1. # chmod +x /etc/rc.d/init.d/nginx

添加至服务管理列表,并让其开机自动启动

  1. # chkconfig --add nginx
  2. # chkconfig nginx on
  3. # service nginx start

而后就可以启动服务并测试了:

在浏览器输入服务器IP地址可以看到如下的欢迎界面,说明nginx已安装成功。

linux
相关资讯       RHEL5  LNMP  LNMP安装 
本文评论   查看全部评论 (1)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款
第 1 楼
* 匿名 发表于 2013/4/5 9:07:52
如果是PHP5.3+的话有Zend Guard Loader代替Zend Optomizer