转载自http://summervast.blog.51cto.com/690507/385511
注意:可能因版本不同,个别指令不起作用,需要注意版本灵活安装,我在安装时也遇到过此问题
开始学习nginx,初步安装nginx,先熟悉一下;参考网上的资料和涨宴老师书籍。
下载需要的版本,0.7版本的是稳定版本,0.8的是开发版本,看个人所好,我用的是nginx-0.8.48;
一、安装
1、检查安装nginx的依赖性,nginx的模块需要第三方库的支持,检查是否安装下列库:
zlib、zlib-devel、openssl、openssl-devel、prce、prce-devel[root@mgmserver ~]# rpm -qa |grep zlibzlib-devel-1.2.3-3zlib-1.2.3-3[root@mgmserver tar_packet]# rpm -qa |grep opensslopenssl-0.9.8e-12.el5openssl-devel-0.9.8e-12.el5[root@mgmserver tar_packet]# rpm -qa |grep pcrepcre-6.6-2.el5_1.7pcre-devel-6.6-2.el5_1.7[root@mgmserver tar_packet]# rpm -qa |grep gcccompat-libgcc-296-2.96-138compat-gcc-34-g77-3.4.6-4gcc-c++-4.1.2-46.el5libgcc-4.1.2-46.el5compat-gcc-34-3.4.6-4compat-gcc-34-c++-3.4.6-4gcc-java-4.1.2-46.el5gcc-4.1.2-46.el5gccp-gfortran-4.1.2-46.el5[root@mgmserver tar_packet]# rpm -qa |grep autoconfautoconf-2.59-12[root@mgmserver tar_packet]# rpm -qa |grep automakeautomake-1.9.6-2.1automake16-1.6.3-8automake15-1.5-16automake17-1.7.9-7automake14-1.4p6-132、添加nginx使用的用户和组 ,[root@mgmserver ~]# groupadd nginx #nginx使用的组;[root@mgmserver ~]# useradd -g nginx nginx #nginx使用用户;3、安装[root@mgmserver ~]# cd /home/tar_packet/[root@mgmserver tar_packet]# tar -zxvf nginx-0.8.48.tar.gz -C /home/install_packet/[root@mgmserver tar_packet]# cd ../install_packet/[root@mgmserver install_packet]# cd nginx-0.8.48/[root@mgmserver nginx-0.8.48]# lsauto CHANGES CHANGES.ru conf configure contrib html LICENSE README src[root@mgmserver nginx-0.8.48]# ./configure --prefix=/usr/local/nginx \> --user=nginx \> --group=nginx \> --with-http_stub_status_module \ #启用“server status"页> --with-http_ssl_module #开启http ssl模块,使nginx可以支持https请求,这个模块需要已经 安装openssl checking for OS + Linux 2.6.18-164.el5 i686checking for C compiler ... foundchecking for gcc builtin atomic operations ... not foundchecking for C99 variadic macros ... foundchecking for gcc variadic macros ... foundchecking for unistd.h ... foundchecking for inttypes.h ... foundchecking for limits.h ... foundchecking for sys/filio.h ... not foundchecking for sys/param.h ... foundchecking for sys/mount.h ... foundchecking for sys/statvfs.h ... foundchecking for crypt.h ... foundchecking for Linux specific featureschecking for epoll ... foundchecking for sendfile() ... foundchecking for sendfile64() ... foundchecking for sys/prctl.h ... foundchecking for prctl(PR_SET_DUMPABLE) ... foundchecking for sched_setaffinity() ... foundchecking for crypt_r() ... foundchecking for sys/vfs.h ... foundchecking for poll() ... foundchecking for /dev/poll ... not foundchecking for kqueue ... not foundchecking for crypt() ... not foundchecking for crypt() in libcrypt ... foundchecking for F_READAHEAD ... not foundchecking for posix_fadvise() ... foundchecking for O_DIRECT ... foundchecking for F_NOCACHE ... not foundchecking for directio() ... not foundchecking for statfs() ... foundchecking for statvfs() ... foundchecking for dlopen() ... not foundchecking for dlopen() in libdl ... foundchecking for sched_yield() ... foundchecking for SO_SETFIB ... not foundchecking for PCRE library ... foundchecking for OpenSSL library ... foundchecking for zlib library ... foundcreating objs/Makefilechecking for int size ... 4 byteschecking for long size ... 4 byteschecking for long long size ... 8 byteschecking for void * size ... 4 byteschecking for uint64_t ... foundchecking for sig_atomic_t ... foundchecking for sig_atomic_t size ... 4 byteschecking for socklen_t ... foundchecking for in_addr_t ... foundchecking for in_port_t ... foundchecking for rlim_t ... foundchecking for uintptr_t ... uintptr_t foundchecking for system endianess ... little endianesschecking for size_t size ... 4 byteschecking for off_t size ... 8 byteschecking for time_t size ... 4 byteschecking for setproctitle() ... not foundchecking for pread() ... foundchecking for pwrite() ... foundchecking for strerror_r() ... found but is not workingchecking for gnu style strerror_r() ... foundchecking for sys_errlist[] ... foundchecking for localtime_r() ... foundchecking for posix_memalign() ... foundchecking for memalign() ... foundchecking for mmap(MAP_ANON|MAP_SHARED) ... foundchecking for mmap("/dev/zero", MAP_SHARED) ... foundchecking for System V shared memory ... foundchecking for struct msghdr.msg_control ... foundchecking for ioctl(FIONBIO) ... foundchecking for struct tm.tm_gmtoff ... foundchecking for struct dirent.d_namlen ... not foundchecking for struct dirent.d_type ... foundConfiguration summary + using system PCRE library + using system OpenSSL library + md5: using OpenSSL library + sha1 library is not used + using system zlib library nginx path prefix: "/usr/local/nginx" nginx binary file: "/usr/local/nginx/sbin/nginx" nginx configuration prefix: "/usr/local/nginx/conf" nginx configuration file: "/usr/local/nginx/conf/nginx.conf" nginx pid file: "/usr/local/nginx/logs/nginx.pid" nginx error log file: "/usr/local/nginx/logs/error.log" nginx http access log file: "/usr/local/nginx/logs/access.log" nginx http client request body temporary files: "client_body_temp" nginx http proxy temporary files: "proxy_temp" nginx http fastcgi temporary files: "fastcgi_temp" nginx http uwsgi temporary files: "uwsgi_temp" nginx http scgi temporary files: "scgi_temp" [root@mgmserver nginx-0.8.48]#make[root@mgmserver nginx-0.8.48]#make install二、启动nginx[root@mgmserver nginx]# /usr/local/webserver/nginx/sbin/nginx -c /usr/local/webserver/nginx/conf/nginx.conf参数"-c"指定了配置文件的路径,如果不加'-c"参数, nginx,会默认加载其安装目录中conf子目录中的nginx.conf文件。
[root@mgmserver nginx-0.8.48]# ps -ef |grep nginx
可以看到一个主nginx的进程信息,一个子进程;如果在安装过程指定了“-pid-path=<path>那么该文件就指定了nginx的主进程号,如果没有指定pid文件的存放路径,nginx.pid默认存放在nginx安装目录的logs子目录下,
[root@mgmserver logs]# ls
access.log error.log nginx.pid[root@mgmserver logs]# cat nginx.pid6019三、nginx的信号控制
◆ TERM,INT 快速关闭
◆ QUIT 从容关闭
◆ HUP 平滑重启,重新加载配置文件
◆ USR1 重新打开日志文件,在切割日志时用途较大;
◆ USR2 平滑升级可执行程序
◆ WINCH 从容关闭工作进程
我们可以直接通过以下命令来完成平滑重启,省下寻找nginx主进程号的步骤;
kill -"信号类型” ‘/usr/local/nginx/logs/nginx.pid'或者nginx的主进程号
(1)、从容停止nginx
[root@mgmserver ~]# kill -QUIT 6019 #nginx主进程号[root@mgmserver logs]# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid`
(2)、快速停止nginx[root@mgmserver logs]# kill -TERM /INT nginx主进程号
[root@mgmserver logs]# kill -TERM /INT `cat /usr/local/nginx/logs/nginx.pid
(3)、强制停止所有的nginx进程
#pkill -9 nginx
(4)、平滑重启nginx
修改了nginx的配置文件要重启nginx;重启之前要检查配置文件是否正确:
[root@mgmserver html]# /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
the configuration file /usr/local/nginx/conf/nginx.conf syntax is okconfiguration file /usr/local/nginx/conf/nginx.conf test is successful[root@mgmserver conf]# kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
注意符号;
nginx的平滑重启kill -HUP Nginx主进程号
或者
kill -HUP ·nginx.pid文件按存放路径·