安装和配置nginx

环境:ubuntu
安装nginx所需的依赖

yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel pcre-devel

 



安装nginx

mkdir nginx-src && cd nginx-src  
wget http://nginx.org/download/nginx-1.24.0.tar.gz  
tar xzf nginx-1.24.0.tar.gz   
cd nginx-1.24.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module make make install whereis nginx nginx: /usr/local/nginx

 

默认的安装路径为:/usr/local/nginx;跳转到其目录下sbin路径下,便可以启动或停止它了。

./nginx -h 查看帮助和版本信息
启动:nginx
停止:nginx -s stop
重启:nginx -s reload

添加到系统服务

    #!/bin/sh  
    # chkconfig: 2345 85 15  
    # Startup script for the nginx Web Server  
    # description: nginx is a World Wide Web server.   
    # It is used to serve HTML files and CGI.  
    # processname: nginx  
    # pidfile: /usr/local/nginx/logs/nginx.pid  
    # config: /usr/local/nginx/conf/nginx.conf  
      
    PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin  
    DESC="nginx deamon"  
    NAME=nginx  
    DAEMON=/usr/local/nginx/sbin/$NAME  
    SCRIPTNAME=/etc/init.d/$NAME  
      
    test -x $DAEMON || exit 0  
      
    d_start(){  
      $DAEMON || echo -n "already running"  
    }  
      
    d_stop(){  
      $DAEMON -s quit || echo -n "not running"  
    }  
      
      
    d_reload(){  
      $DAEMON -s reload || echo -n "can not reload"  
    }  
      
    case "$1" in  
    start)  
      echo -n "Starting $DESC: $NAME"  
      d_start  
      echo "."  
    ;;  
    stop)  
      echo -n "Stopping $DESC: $NAME"  
      d_stop  
      echo "."  
    ;;  
    reload)  
      echo -n "Reloading $DESC conf..."  
      d_reload  
      echo "reload ."  
    ;;  
    restart)  
      echo -n "Restarting $DESC: $NAME"  
      d_stop  
      sleep 2  
      d_start  
      echo "."  
    ;;  
    *)  
      echo "Usage: $ScRIPTNAME {start|stop|reload|restart}" >&2  
      exit 3  
    ;;  
    esac  
      
    exit 0  



保存退出后,再使用下面的命令,使其可执行;然后,添加配置并查看。
chmod +x /etc/init.d/nginx  
chkconfig --add nginx  
chkconfig nginx on/off  
chkconfig --list nginx  
nginx 0:off 1:off 2:on 3:on 4:on 5:on 6:off  

配置Nginx反向代理Tomcat

在/usr/local/nginx/conf
nginx.conf中配置:

 location / {
            root   html;
            index  index.html index.htm;
            proxy_pass http://localhost:8181;    //配置tomcat的路径 使其被nginx代理
        }


重启nginx:
/usr/local/nginx/sbin目录下: nginx -s reload

posted on 2017-05-15 15:51  执迷有误  阅读(19)  评论(0)    收藏  举报

导航