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

[经验分享] nginx 编译安装与配置详解

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-11-21 12:49:12 | 显示全部楼层 |阅读模式
一、编译安装

1、使用yum安装所需的包,虽然需要编译几个依赖包,pcre、zlib、openssl
yum -y groupinstall "Development Tools""Server Platform Development"
yum install pcre-devel zlib-devel openssl-devel gcc* (一般系统装好了,以下的这几个包openssl、zlib、pcre都已经安装上了,注意: pcre-devel zlib-devel openssl-devel这几个devel包要装上,不然编译的时候会报错)


2、添加用户和组
groupadd -r nginx
useradd -r -g nginx nginx

3、解压安装文件

tar -zxvf nginx-1.10.1.tar.gz
cd nginx-1.10.1


4、配置选项
./configure --prefix=/usr/local/nginx #nginx家目录
--sbin-path=/usr/sbin #nginx主程序路径
--conf-path=/etc/nginx/nginx.conf #nginx主配置文件路径

--error-log-path=/var/log/nginx/error.log #错误日志路径

--http-log-path=/var/log/nginx/access.log #访问日志路径
--pid-path=/var/run/nginx/nginx.pid #进程ID路径

--lock-path=/var/lock/nginx.lock #nginx锁文件路径

--user=nginx #worker进程所属的用户名称

--group=nginx #worker进程所属的组名称

--with-http_ssl_module #启用http_ssl模块

--with-http_flv_module #启用服务端伪流媒体模块

--with-http_stub_status_module #启用健康检查模块

--with-http_gzip_static_module #启用ngnix 的静态缓存模块
--http-client-body-temp-path=/var/tmp/nginx/client #启用为http连接的请求实体临时文件设置路径
--http-proxy-temp-path=/var/tmp/nginx/proxy #为http代理临时文件设置路径
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi #为http fastcgi临时文件设置路径
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi #为http uwcgi临时文件设置路径
--http-scgi-temp-path=/var/tmp/nginx/scgi  #为http scgi临时文件设置路径
--with-pcre #使用pcre库文件

--with-stream #启用TCP/UDP代理模块



运行配置检查:

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + md5: using OpenSSL library
  + sha1: using OpenSSL library
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/sbin/nginx"
  nginx modules path: "/usr/local/modules"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/var/run/nginx/nginx.pid"
  nginx error log file: "/var/log/nginx/error.log"
  nginx http access log file: "/var/log/nginx/access.log"
  nginx http client request body temporary files: "/var/tmp/nginx/client/"
  nginx http proxy temporary files: "/var/tmp/nginx/proxy/"
  nginx http fastcgi temporary files: "/var/tmp/nginx/fcgi/"
  nginx http uwsgi temporary files: "/var/tmp/nginx/uwsgi"
  nginx http scgi temporary files: "/var/tmp/nginx/scgi

5、编译和安装

make && make install


6、在/var/tmp目录下建立nginx目录
mkdir -p /var/tmp/nginx


7、检查配置文件是否有语法错误

[iyunv@localhost ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful



8、编辑服务启动脚本
vim /etc/init.d/nginx
#! /bin/bash
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig:   - 85 15
# description:  Nginx is an HTTP(S) server, HTTP(S) reverse \
#                          proxy and IMAP/POP3 proxy server
#
# processname: nginx
# config:         /etc/nginx/nginx.conf
# pidfile:       /var/run/nginx/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/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/nginx.lock
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
  sleep 1
  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

9、启动nginx


[iyunv@localhost init.d]# service nginx start
正在启动 nginx:                                           [确定]


10、停止nginx
[iyunv@localhost init.d]# service nginx stop
停止 nginx:                                               [确定]




11、查看进程情况
[iyunv@localhost init.d]# ps -ef|grep nginx
root      10342      1  0 02:04 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx     10344  10342  0 02:04 ?        00:00:00 nginx: worker process                  
root      10350   1613  0 02:07 pts/0    00:00:00 grep nginx

12、查看监听的端口

[iyunv@localhost init.d]# netstat -tnlp|grep nginx
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      10342/nginx


运维网声明 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.iyunv.com/thread-303455-1-1.html 上篇帖子: nginx常用配置文件模块 下篇帖子: Nginx负载均衡Tomcat、Resin实现动静分离
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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