nginx安裝
高性能web服務器
1.1下載
[root@localhost soft]# wget http://nginx.org/download/nginx-1.4.2.tar.gz
[root@localhost soft]# tar -zxf nginx-1.4.2.tar.gz
[root@localhost nginx-1.4.2]# yum install pcre pcre-devel#rewrite模塊使用
[root@localhost nginx-1.4.2]# ./configure --prefix=/usr/local/nginx
root@localhost nginx-1.4.2]# make && make install
[root@localhost nginx-1.4.2]# cd /usr/local/nginx
[root@localhost nginx]# ls
conf 配置文件
html 網頁文件
logs 日誌文件
sbin 進程文件
[root@localhost nginx]# ./sbin/nginx啓動nginx
[root@localhost nginx]# ps aux|grep nginx
root 7686 0.0 0.0 20292 608 ? Ss 02:56 0:00 nginx: master process ./sbin/nginx ################master
nobody 7687 0.0 0.1 20688 1160 ? S 02:56 0:00 nginx: worker process# worker
root 8228 0.0 0.0 103248 864 pts/0 S+ 03:04 0:00 grep nginx
[root@localhost nginx]# kill -INT 7686
Nginx的信號控制
TERM, INT Quick shutdown
QUIT Graceful shutdown 優雅的關閉進程,即等請求結束後再關閉
HUP Configuration reload ,Start the new worker processes with
a new configuration Gracefully shutdown the old worker processes
改變配置文件,平滑的重讀配置文件
USR1 Reopen the log files 重讀日誌,在日誌按月/日分割時有用
USR2 Upgrade Executable on the fly 平滑的升級#版本升級用,好比說1.4升級到1.6覆蓋安裝nginx
WINCH Gracefully shutdown the worker processes 優雅關閉舊的進程(配合USR2來進行升級)
具體語法:
Kill -信號選項 nginx的主進程號
[root@localhost nginx]# vi conf/nginx.conf
location / {
root html;
index ab.html index.html index.htm;
}
[root@localhost nginx]# vi html/ab.html
<html>
ab
</html>
[root@localhost nginx]# ./sbin/nginx
http://192.168.88.170/
[root@localhost nginx]# vi conf/nginx.conf
location / {
root html;
index index.html index.htm;
}
[root@localhost nginx]# ps aux|grep nginx
root 8912 0.0 0.0 20292 608 ? Ss 03:19 0:00 nginx: master process ./sbin/nginx
nobody 8913 0.0 0.1 20688 1396 ? S 03:19 0:00 nginx: worker process
root 8942 0.0 0.0 103248 864 pts/0 S+ 03:22 0:00 grep nginx
[root@localhost nginx]# kill -HUP 8912
http://192.168.88.170/
[root@localhost nginx]# vi html/ab.html
<html>
<script>window.location.href='/'</script>
ab
</html>
[root@localhost nginx]# kill -HUP 8912
[root@localhost nginx]# ls logs/
access.log error.log nginx.pid
不能直接mv 文件名由於他們的inodey相同
Kill -USR1 `cat /xxx/path/log/nginx.pid`重作日誌
[root@localhost nginx]# sbin/nginx -h
nginx version: nginx/1.4.2
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
-s signal : send signal to a master process: 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 of configuration file
[root@localhost nginx]# sbin/nginx -s reload
[root@localhost nginx]# sbin/nginx -s stop
[root@localhost nginx]# sbin/nginx -s reopen #USR1
[root@localhost nginx]# sbin/nginx -t
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
html