深刻理解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


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值