设为首页 收藏本站
查看: 1774|回复: 0

[经验分享] centos6.4 32位 详细安装Nginx

[复制链接]

尚未签到

发表于 2018-11-16 09:32:25 | 显示全部楼层 |阅读模式
  1.安装Nginx前期准备:
  1)Nginx的配置及运行需要pcre、zlib等软件包的支持,因此应预先安装这些软件的开发包(devel),以便提供相应的库和头文件,确保Ngnix的安装顺利完成。
  Yum –y install pcre-devel zlib-devel
  2)
  创建运行用户、组,建议为其创建专门的用户账号,以便更准确地控制其访问权限,增加灵活性、降低安全风险。
  useradd –M –s /sbin/nologin nginx
  3)编译安装Nginx
  如果在编译的时候出现下面的状况,是因为gcc没有安装,不信的话,可以
  Rpm –ql | grep gcc* 看看
  在安装gcc的时候如果出现下面情况是因为gpgcheck=1,而你的key又导入失败,这时key不能用,要么就找个新的key地址,要不就把gpgcheck=0,就ok了
DSC0000.jpg

  做完这步就可以编译安装Nginx了
  3)
  编译安装Nginx
  [root@68Q /]# tar zxvf nginx-1.4.2.tar.gz
  [root@68Q /]# cd nginx-1.4.2
  [root@68Q nginx-1.4.2]#
  [root@68Q nginx-1.4.2]# ./configure --prefix=/usr/local/nginx--user=nginx --group=nginx
  [root@68Q nginx-1.4.2]# make && make install
  为了使Nginx服务器的运行更加方便,可以为nginx创建链接文件,以便管理员直接执行”nginx”命令就可以调用nginx的主程序。
  [root@68Q nginx-1.4.2]# ln -s /usr/local/nginx/sbin/nginx/usr/local/sbin/
DSC0001.jpg

  1.Nginx 的运行控制
  1)检查配置文件
  与Apache的主程序httpd类似,nginx的主程序也提供了“-t”选项用来对配置文件进行检查,以便找出不当或错误的配置。配置文件nginx.conf默认位于安装目录下的conf/子目录中,若要检查其他位置的配置文件,可使用“-c”选项来指定路径。
  [root@68Qnginx-1.4.2]# nginx -t
  nginx:the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  nginx:configuration file /usr/local/nginx/conf/nginx.conf test is successful
  [root@68Q nginx-1.4.2]#
  2)
  启动nginx
  [root@68Q nginx-1.4.2]# nginx
  通过检查nginx程序的监听状态,或者在浏览器中访问此web服务(默认页面将显示“Welcom to nginx!”),可以确认nginx服务是否正常运行。
  [root@68Qnginx-1.4.2]# netstat -anpt | grep nginx
  tcp00 0.0.0.0:800.0.0.0:*LISTEN5443/nginx
  [root@68Q nginx-1.4.2]#
  [root@68Qnginx-1.4.2]# elinks http://localhost
  Welcome to nginx!
  Welcome tonginx!
  If you see this page, the nginx web serveris successfully installed and
  working. Further configuration isrequired.
  For online documentation and support pleaserefer to nginx.org.
  Commercial support is available atnginx.com.
  Thank you forusing nginx.
  访问成功
  主程序nginx支持标准的进程信号,通过kill或killall命令发送HUP信号表示重载配置,QUIT信号表示退出进程。KILL信号表示杀死进程。(例如,若使用killall命令,重载配置、停止服务的操作分别如下(通过-s指定信号种类)
  [root@68Qnginx-1.4.2]# killall -s HUP nginx选项-s HUP 等同于 -1
  [root@68Qnginx-1.4.2]# killall -s QUIT nginx选项-s QUIT 等同于 -3
  [root@68Q nginx-1.4.2]#
  当nginx进程运行时,PID号默认存放在logs/目录下的nginx.pid文件中,因此若要改用kill命令,也可以根据nginx.pid文件中的PID号来进行控制。
  3)使用nginx服务脚本
  [root@68Q nginx-1.4.2]# vi /etc/init.d/nginx
  [root@68Qnginx-1.4.2]# vi /etc/init.d/nginx
  #!/bin/sh
  #
  # nginx - this script starts and stops the nginx daemin
  #
  # chkconfig:   - 85 15
  # description:  Nginx is an HTTP(S) server,HTTP(S) reverse \
  #              proxy and IMAP/POP3 proxy server
  # processname: nginx
  # config:     /usr/local/nginx/conf/nginx.conf
  # pidfile:    /usr/local/nginx/logs/nginx.pid
  # Source function library.
  . /etc/rc.d/init.d/functions
  # Source networking configuration.
  . /etc/sysconfig/network
  # Check that networking is up.
  [ "$NETWORKING" = "no" ] &&exit 0
  nginx="/usr/local/nginx/sbin/nginx"
  prog=$(basename $nginx)
  NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
  lockfile=/var/lock/subsys/nginx
  start() {
  [ -x $nginx ] || exit 5
  [ -f $NGINX_CONF_FILE ] || exit 6
  echo -n $"Starting $prog:"
  daemon $nginx -c $NGINX_CONF_FILE
  retval=$?
  echo
  [ $retval -eq 0 ] && touch$lockfile
  return $retval
  }
  stop() {
  echo -n $"Stopping $prog:"
  killproc $prog -QUIT
  retval=$?
  echo
  [ $retval -eq 0 ] && rm -f$lockfile
  return $retval
  }
  restart() {
  configtest || return $?
  stop
  start
  }
  reload() {
  configtest || return $?
  echo -n $"Reloading $prog:"
  killproc $nginx -HUP
  RETVAL=$?
  echo
  }
  force_reload() {
  restart
  }
  configtest() {
  $nginx -t -c $NGINX_CONF_FILE
  }
  rh_status() {
  status $prog
  }
  rh_status_q() {
  rh_status >/dev/null 2>&1
  }
  case "$1" in
  start)
  rh_status_q &&exit 0
  $1
  ;;
  stop)
  rh_status_q || exit 0
  $1
  ;;
  restart|configtest)
  $1
  ;;
  reload)
  rh_status_q || exit 7
  $1
  ;;
  force-reload)
  force_reload
  ;;
  status)
  rh_status
  ;;
  condrestart|try-restart)
  rh_status_q || exit 0
  ;;
  *)
  echo $"Usage: $0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
  exit 2
  esac
  [root@68Qnginx-1.4.2]# chmod +x /etc/init.d/nginx
  [root@68Qnginx-1.4.2]# chkconfig --add nginx
  [root@68Q nginx-1.4.2]#
  通过脚本,nginx就可以正常的使用了。
DSC0002.jpg



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-635640-1-1.html 上篇帖子: Nginx(二) 虚拟主机配置 下篇帖子: awstats 统计 nginx日志切割
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表