首页 > 代码库 > 深刻理解Nginx之Nginx完整安装

深刻理解Nginx之Nginx完整安装

1.   Nginx安装

1.1预先准备

CentOS系统下,安装Nginx的库包依赖。

安装命令例如以下:

sudo yum groupinstall "DevelopmentTools"
sudo yum install pcre pcre-devel
sudo yum install zlib zlib-devel
yum install perl-ExtUtils-Embed
sudo yum install openssl openssl-devel


1.2 安装

    最重要的特性和基于http和https内容的模块化,configuration參数能够这样:

./configure  --prefix=/usr/local/nginx-1.5.13--user=app --group=app --with-http_ssl_module --with-http_realip_module



  安装全部必要的模块:

./configure --user=app --group=app--with-http_ssl_module --with-http_realip_module --with-http_addition_module--with-http_xslt_module --with-http_image_filter_module--with-http_geoip_module --withhttp_sub_module --with-http_dav_module--with-http_flv_module --withhttp_mp4_module --with-http_gzip_static_module--with-http_random_index_module --with-http_secure_link_module--with-http_stub_status_module --with-http_perl_module--with-http_degradation_module


    使用root用户,或者管理员用户来运行这个命令。

sudo make & sudo make install

….
cp conf/scgi_params            ‘/usr/local/nginx-1.5.13/conf/scgi_params.default‘
test -f ‘/usr/local/nginx-1.5.13/conf/nginx.conf‘               || cp conf/nginx.conf‘/usr/local/nginx-1.5.13/conf/nginx.conf‘
cp conf/nginx.conf ‘/usr/local/nginx-1.5.13/conf/nginx.conf.default‘
test -d ‘/usr/local/nginx-1.5.13/logs‘          || mkdir -p‘/usr/local/nginx-1.5.13/logs‘
test -d ‘/usr/local/nginx-1.5.13/logs‘ ||               mkdir -p‘/usr/local/nginx-1.5.13/logs‘
test -d ‘/usr/local/nginx-1.5.13/html‘          || cp -R html‘/usr/local/nginx-1.5.13‘
test -d ‘/usr/local/nginx-1.5.13/logs‘ ||               mkdir -p‘/usr/local/nginx-1.5.13/logs‘
make[1]: Leaving directory `/home/app/Downloads/nginx-1.5.13‘


1.3 測试

測试Nginx配置是否正确。能够使用下列命令:

启动Nginx

#sudo  /usr/local/nginx-1.5.13/sbin/nginx


浏览页面http://localhost,得到的结果:

Welcome to nginx!

2 使用命令

成功安装Nginx后,有必要了解一下主要的命令。

nginx –s stop Stops the daemon immediately (using the TERM signal)
nginx –s quit Stops the daemon gracefully (using the QUIT signal)
nginx –s reopen Reopens the log files
nginx –s reload Reloads the configuration


停掉nginx进程,输入命令:

killall nginx

測试配置是否成功:

[app@hadoop-master sbin]$ sudo/usr/local/nginx/sbin/nginx  -t
[sudo] password for app:
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


了解有关Nginx命令,输入:

[app@hadoop-mastersbin]$ ./nginx -h
nginxversion: nginx/1.5.13
Usage:nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
 
Options:
  -?,-h        : this help
  -v           : show version and exit
  -V           : show version and configure options then exit
  -t           : test configuration and exit
  -q           : suppress non-error messages during configuration testing
  -ssignal     : send signal to a masterprocess: stop, quit, reopen, reload
  -p prefix    : set prefix path (default: /usr/local/nginx/)
  -c filename  : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out ofconfiguration file


以下一个表中呈现了不同执行级别和它们的含义。


对系统的进程的执行级别有一定了解后,我们将Nginx加到系统服务(service)中。

须要在/etc/init.d文件夹下,创建nginx脚本。比如,nginx脚本能够这样配置:

---------------------------------------------------------------------------------------------------

  

保持后,改动运行权限。

#sudo chmod +x /etc/init.d/nginx


又一次启动Nginx:

sudo /usr/init.d/nginx reload


加入nginx到自己主动启动文件列表中:

sudo chkconfig –add nginx


检測nginx的执行级别:

[app@hadoop-master~]$ sudo chkconfig --list nginx
nginx           0:off   1:off  2:off   3:off   4:off  5:off   6:off


深刻理解Nginx之Nginx完整安装