3、停止Nginx
当Nginx服务启动起来后,就会在原本空目录/usr/local/nginx/logs/下自动生成3个文件:
access.log error.log nginx.pid
这里包含nginx的主进程号:nginx.pid ,我们可以通过如上的ps命令查看、也可以直接cat出来
3.1 从容停止Nginx
kill -QUIT Nginx主进程号
# kill -QUIT `cat /usr/local/nginx/logs/nginx.pid`
3.2 快速停止Nginx
kill -TERM Nginx主进程号
# kill -TERM `cat /usr/local/nginx/logs/nginx.pid`
4、重启Nginx
如果改变了Nginx的主配置文件,想重启Nginx,可以先检查Nginx的配置文件是否正确后才发送系统信号给Nginx主进程的方式进行,检查方法如下:
# /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
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
只有出现如上OK信息才会加载新的配置文件.
4.1 平滑重启Nginx
kill -HUP Nginx主进程号
# kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
如果Nginx本身都还没启动,平滑重启可是会报错的.
5、Nginx的信号控制
TERM,INT 快速关闭
QUIT 从容关闭
HUP 平滑重启
USR1 重新打开日志文件、在切割日志时用途大
USR2 平滑升级可执行程序
WINCH 从容关闭工作进程
三、Nginx的基本配置与优化
看Nginx的主配置文件,可以发现原本的配置文件非常简练
- # grep -v "#" nginx.conf
- worker_processes 1;
- events {
- worker_connections 1024;
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- sendfile on;
- keepalive_timeout 65;
- server {
- listen 80;
- server_name localhost;
- location / {
- root html;
- index index.html index.htm;
- }
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- }
- }
1、配置虚拟主机
1.1、配置基于IP的虚拟主机
添加虚拟网卡:
ifconfig eth0:1 110.65.99.209 broadcast 110.65.99.255 netmask 255.255.252.0 up
route add -host 110.65.99.209 dev eth0:1
ifconfig eth0:2 110.65.99.210 broadcast 110.65.99.255 netmask 255.255.252.0 up
route add -host 110.65.99.210 dev eth0:2
如上命令最好写进/etc/rc.local中系统开机自动创建.
或者直接cp ifcfg-eth0 ifcfg-eth0:1
修改Nginx的主配置文件: /usr/local/nginx/conf/nginx.conf
在原本定义的一个server之后添加如下两个虚拟主机
- ###############server2################################
- server {
- listen 110.65.99.209:80;
- server_name server2;
- access_log logs/server2.access.log combined;
- location / {
- index index.html index.htm;
- root /usr/local/nginx/server2;
- }
- }
- ###############server3################################
- server {
- listen 110.65.99.210:80;
- server_name server3;
- access_log logs/server3.access.log combined;
- location / {
- index index.html index.htm;
- root /usr/local/nginx/server3;
- }
- }
然后创建目录server2和server3,并且在各自目录下创建index.html测试文件
检查配置文件是否写正确,然后才平滑重启Nginx
# /usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
# kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
测试:
# links http://110.65.99.209
# links http://110.65.99.210
测试后在/usr/local/nginx/logs目录下会自动创建Log日志文件
server2.access.log server3.access.log
# cat server2.access.log
110.65.99.209 - - [21/Apr/2011:22:34:11 0800] "GET / HTTP/1.1" 200 8 "-" "ELinks/0.11.1 (textmode; Linux; 142x38-2)"
# cat server3.access.log
110.65.99.210 - - [21/Apr/2011:22:34:24 0800] "GET / HTTP/1.1" 200 8 "-" "ELinks/0.11.1 (textmode; Linux; 142x38-2)"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="3600"
eaccelerator.shm_prune_period="3600"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"
|