開(kāi)始學(xué)習(xí)nginx,初步安裝nginx,先熟悉一下;參考網(wǎng)上的資料和漲宴老師書(shū)籍。
http://nginx.org/en/download.html
下載需要的版本,0.7版本的是穩(wěn)定版本,0.8的是開(kāi)發(fā)版本,看個(gè)人所好,我用的是nginx-0.8.48;
一、安裝
1、檢查安裝nginx的依賴性,nginx的模塊需要第三方庫(kù)的支持,檢查是否安裝下列庫(kù):
zlib、zlib-devel、openssl、openssl-devel、prce、prce-devel
[root@mgmserver ~]# rpm -qa |grep zlib
zlib-devel-1.2.3-3
zlib-1.2.3-3
[root@mgmserver tar_packet]# rpm -qa |grep openssl
openssl-0.9.8e-12.el5
openssl-devel-0.9.8e-12.el5
[root@mgmserver tar_packet]# rpm -qa |grep pcre
pcre-6.6-2.el5_1.7
pcre-devel-6.6-2.el5_1.7
[root@mgmserver tar_packet]# rpm -qa |grep gcc
compat-libgcc-296-2.96-138
compat-gcc-34-g77-3.4.6-4
gcc-c++-4.1.2-46.el5
libgcc-4.1.2-46.el5
compat-gcc-34-3.4.6-4
compat-gcc-34-c++-3.4.6-4
gcc-java-4.1.2-46.el5
gcc-4.1.2-46.el5
gccp-gfortran-4.1.2-46.el5
[root@mgmserver tar_packet]# rpm -qa |grep autoconf
autoconf-2.59-12
[root@mgmserver tar_packet]# rpm -qa |grep automake
automake-1.9.6-2.1
automake16-1.6.3-8
automake15-1.5-16
automake17-1.7.9-7
automake14-1.4p6-13
2、添加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]# ls
auto 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"頁(yè)
> --with-http_ssl_module #開(kāi)啟http ssl模塊,使nginx可以支持https請(qǐng)求,這個(gè)模塊需要已經(jīng)
安裝openssl
checking for OS
+ Linux 2.6.18-164.el5 i686
checking for C compiler ... found
checking for gcc builtin atomic operations ... not found
checking for C99 variadic macros ... found
checking for gcc variadic macros ... found
checking for unistd.h ... found
checking for inttypes.h ... found
checking for limits.h ... found
checking for sys/filio.h ... not found
checking for sys/param.h ... found
checking for sys/mount.h ... found
checking for sys/statvfs.h ... found
checking for crypt.h ... found
checking for Linux specific features
checking for epoll ... found
checking for sendfile() ... found
checking for sendfile64() ... found
checking for sys/prctl.h ... found
checking for prctl(PR_SET_DUMPABLE) ... found
checking for sched_setaffinity() ... found
checking for crypt_r() ... found
checking for sys/vfs.h ... found
checking for poll() ... found
checking for /dev/poll ... not found
checking for kqueue ... not found
checking for crypt() ... not found
checking for crypt() in libcrypt ... found
checking for F_READAHEAD ... not found
checking for posix_fadvise() ... found
checking for O_DIRECT ... found
checking for F_NOCACHE ... not found
checking for directio() ... not found
checking for statfs() ... found
checking for statvfs() ... found
checking for dlopen() ... not found
checking for dlopen() in libdl ... found
checking for sched_yield() ... found
checking for SO_SETFIB ... not found
checking for PCRE library ... found
checking for OpenSSL library ... found
checking for zlib library ... found
creating objs/Makefile
checking for int size ... 4 bytes
checking for long size ... 4 bytes
checking for long long size ... 8 bytes
checking for void * size ... 4 bytes
checking for uint64_t ... found
checking for sig_atomic_t ... found
checking for sig_atomic_t size ... 4 bytes
checking for socklen_t ... found
checking for in_addr_t ... found
checking for in_port_t ... found
checking for rlim_t ... found
checking for uintptr_t ... uintptr_t found
checking for system endianess ... little endianess
checking for size_t size ... 4 bytes
checking for off_t size ... 8 bytes
checking for time_t size ... 4 bytes
checking for setproctitle() ... not found
checking for pread() ... found
checking for pwrite() ... found
checking for strerror_r() ... found but is not working
checking for gnu style strerror_r() ... found
checking for sys_errlist[] ... found
checking for localtime_r() ... found
checking for posix_memalign() ... found
checking for memalign() ... found
checking for mmap(MAP_ANON|MAP_SHARED) ... found
checking for mmap("/dev/zero", MAP_SHARED) ... found
checking for System V shared memory ... found
checking for struct msghdr.msg_control ... found
checking for ioctl(FIONBIO) ... found
checking for struct tm.tm_gmtoff ... found
checking for struct dirent.d_namlen ... not found
checking for struct dirent.d_type ... found
Configuration 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
二、啟動(dòng)nginx
[root@mgmserver nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
參數(shù)"-c"指定了配置文件的路徑,如果不加'-c"參數(shù), nginx,會(huì)默認(rèn)加載其安裝目錄中conf子目錄中的nginx.conf文件。
[root@mgmserver nginx-0.8.48]# ps -ef |grep nginx
可以看到一個(gè)主nginx的進(jìn)程信息,一個(gè)子進(jìn)程;如果在安裝過(guò)程指定了“-pid-path=<path>那么該文件就指定了nginx的主進(jìn)程號(hào),如果沒(méi)有指定pid文件的存放路徑,nginx.pid默認(rèn)存放在nginx安裝目錄的logs子目錄下,
[root@mgmserver logs]# ls
access.log error.log nginx.pid
[root@mgmserver logs]# cat nginx.pid
6019
三、nginx的信號(hào)控制
◆ TERM,INT 快速關(guān)閉
◆ QUIT 從容關(guān)閉
◆ HUP 平滑重啟,重新加載配置文件
◆ USR1 重新打開(kāi)日志文件,在切割日志時(shí)用途較大;
◆ USR2 平滑升級(jí)可執(zhí)行程序
◆ WINCH 從容關(guān)閉工作進(jìn)程
我們可以直接通過(guò)以下命令來(lái)完成平滑重啟,省下尋找nginx主進(jìn)程號(hào)的步驟;
kill -"信號(hào)類型” ‘/usr/local/nginx/logs/nginx.pid'或者nginx的主進(jìn)程號(hào)
(1)、從容停止nginx
[root@mgmserver ~]# kill -QUIT 6019 #nginx主進(jìn)程號(hào)
[root@mgmserver logs]# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid`
(2)、快速停止nginx
[root@mgmserver logs]# kill -TERM /INT nginx主進(jìn)程號(hào)
[root@mgmserver logs]# kill -TERM /INT `cat /usr/local/nginx/logs/nginx.pid
(3)、強(qiáng)制停止所有的nginx進(jìn)程
#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 ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
[root@mgmserver conf]# kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
注意符號(hào);
nginx的平滑重啟
kill -HUP Nginx主進(jìn)程號(hào)
或者
kill -HUP ·nginx.pid文件按存放路徑·
聯(lián)系客服