天天看點

nginx學習(一):基本安裝

轉載自http://summervast.blog.51cto.com/690507/385511 

注意:可能因版本不同,個别指令不起作用,需要注意版本靈活安裝,我在安裝時也遇到過此問題 

開始學習nginx,初步安裝nginx,先熟悉一下;參考網上的資料和漲宴老師書籍。

<a href="http://nginx.org/en/download.html" target="_blank">http://nginx.org/en/download.html</a>

下載下傳需要的版本,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 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 \

&gt; --user=nginx \

&gt; --group=nginx \

&gt; --with-http_stub_status_module \     #啟用“server status"頁

&gt; --with-http_ssl_module                       #開啟http ssl子產品,使nginx可以支援https請求,這個子產品需要已經

                                                                         安裝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

二、啟動nginx

[root@mgmserver nginx]# /usr/local/webserver/nginx/sbin/nginx -c /usr/local/webserver/nginx/conf/nginx.conf

參數"-c"指定了配置檔案的路徑,如果不加'-c"參數, nginx,會預設加載其安裝目錄中conf子目錄中的nginx.conf檔案。

<a href="http://img1.51cto.com/attachment/201008/143045884.png" target="_blank"></a>

nginx學習(一):基本安裝
nginx學習(一):基本安裝

[root@mgmserver nginx-0.8.48]# ps -ef |grep nginx

nginx學習(一):基本安裝

可以看到一個主nginx的程序資訊,一個子程序;如果在安裝過程指定了“-pid-path=&lt;path&gt;那麼該檔案就指定了nginx的主程序号,如果沒有指定pid檔案的存放路徑,nginx.pid預設存放在nginx安裝目錄的logs子目錄下,

[root@mgmserver logs]# ls

access.log  error.log  nginx.pid

[root@mgmserver logs]# cat nginx.pid

6019

三、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 ok

configuration 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檔案按存放路徑·

若轉載請注明出處!若有疑問,請回複交流!

繼續閱讀