首页 > 代码库 > 深刻理解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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。