三、Java运行环境之 cent os6.8 64位安装nginx,os6.8nginx


文章转载:http://blog.csdn.net/tao_627/article/details/45249267

根据工作需要,现在需要安装nginx服务器,本来可以直接安装别人制作好的rpm包的,但是本着爱折腾和时刻尝鲜的精神,我决定从官网下载最新的nginx源码来安装,下面记录了我的安装过程。

下面的安装假定是以root用户登录并执行
1.安装依赖库
这些依赖库主要有g++、gcc、openssl-devel、pcre-devel和zlib-devel 
yum -y install make gcc gcc-c++ glibc glibc-devel lsof   
yum -y install pcre pcre-devel  
yum -y install zlib zlib-devel  
yum -y install openssl openssl--devel 

2.下载源码包
cd /usr/local/src
wget -d "http://nginx.org/download/nginx-1.8.0.tar.gz"
tar zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_realip_module --with-http_ssl_module 
make -j 4
make install

3.验证性启动nginx
注意,在没有设置nginx为系统服务之前,这里仅是验证性的启动测试。使用下面的命令查看nginx可执行程序的路径
whereis nginx
一般默认在/usr/local/nginx目录下面
ulimit -SHn 65535
/usr/local/nginx/sbin/nginx


4.添加nginx为系统服务
添加如下文件

vim /etc/init.d/nginx

[html] view plain copy
  1. #!/bin/sh  
  2. #  
  3. # nginx - this script starts and stops the nginx daemon  
  4. #  
  5. # chkconfig:   - 85 15  
  6. # description: Nginx is an HTTP(S) server, HTTP(S) reverse \  
  7. #               proxy and IMAP/POP3 proxy server  
  8. # processname: nginx  
  9. # config:      /etc/nginx/nginx.conf  
  10. # config:      /etc/sysconfig/nginx  
  11. # pidfile:     /var/run/nginx.pid  
  12. # Source function library.  
  13. . /etc/rc.d/init.d/functions  
  14. # Source networking configuration.  
  15. . /etc/sysconfig/network  
  16. # Check that networking is up.  
  17. [ "$NETWORKING" = "no" ] && exit 0  
  18. nginx="/usr/local/nginx/sbin/nginx"  
  19. prog=$(basename $nginx)  
  20. NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"  
  21. [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx  
  22. lockfile=/var/lock/subsys/nginx  
  23. start() {  
  24.     [ -x $nginx ] || exit 5  
  25.     [ -f $NGINX_CONF_FILE ] || exit 6  
  26.     echo -n $"Starting $prog: "  
  27.     daemon $nginx -c $NGINX_CONF_FILE  
  28.     retval=$?  
  29.     echo  
  30.     [ $retval -eq 0 ] && touch $lockfile  
  31.     return $retval  
  32. }  
  33. stop() {  
  34.     echo -n $"Stopping $prog: "  
  35.     killproc $prog -QUIT  
  36.     retval=$?  
  37.     echo  
  38.     [ $retval -eq 0 ] && rm -f $lockfile  
  39.     return $retval  
  40. killall -9 nginx  
  41. }  
  42. restart() {  
  43.     configtest || return $?  
  44.     stop  
  45.     sleep 1  
  46.     start  
  47. }  
  48. reload() {  
  49.     configtest || return $?  
  50.     echo -n $"Reloading $prog: "  
  51.     killproc $nginx -HUP  
  52. RETVAL=$?  
  53.     echo  
  54. }  
  55. force_reload() {  
  56.     restart  
  57. }  
  58. configtest() {  
  59. $nginx -t -c $NGINX_CONF_FILE  
  60. }  
  61. rh_status() {  
  62.     status $prog  
  63. }  
  64. rh_status_q() {  
  65.     rh_status >/dev/null 2>&1  
  66. }  
  67. case "$1" in  
  68.     start)  
  69.         rh_status_q && exit 0  
  70.     $1  
  71.         ;;  
  72.     stop)  
  73.         rh_status_q || exit 0  
  74.         $1  
  75.         ;;  
  76.     restart|configtest)  
  77.         $1  
  78.         ;;  
  79.     reload)  
  80.         rh_status_q || exit 7  
  81.         $1  
  82.         ;;  
  83.     force-reload)  
  84.         force_reload  
  85.         ;;  
  86.     status)  
  87.         rh_status  
  88.         ;;  
  89.     condrestart|try-restart)  
  90.         rh_status_q || exit 0  
  91.             ;;  
  92.     *)      
  93.       echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"  
  94.         exit 2  
  95. esac  

chmod +x /etc/init.d/nginx
注册 nginx 服务
chkconfig --add nginx
chkconfig --list nginx
假如查看到nginx服务在各种级别下,都没有打开,可以再次使用下面的命令明确指出在不同级别下打开:
chkconfig --level 2345 nginx on
再次采用
chkconfig --list nginx
查看,是否在上述各级别下已经打开。这里之所以要如此强调,是希望在断电后nginx服务能自动重启。


4.修改配置文件nginx.conf

主要是根据业务逻辑来配置nginx.conf,这里忽略具体内容


配置完成后,重新测试并加载nginx.conf
service nginx configtest
service nginx reload
让nginx在新的配置下运行就可以了


5.安装中出现的问题和错误
因为nginx.conf中出现问题,显示错误如下:
nginx: [emerg] unknown directive "lua_shared_dict" in /usr/local/nginx/conf/nginx.conf:11

nginx: [emerg] unknown directive "rewrite_by_lua_file" in /usr/local/nginx/conf/nginx.conf:136

解决方法

这两个报错,是因为nginx.conf中添加了这两个指令,将对应配置及逻辑删除就可以了。

参考链接
https://www.centos.bz/2012/12/openresty-nginx-block-cc-attack-deploy/
我暂时将它们注释掉    
0
0
查看评论

相关内容

    暂无相关文章