ngixn配置

记录一下nginx的配置,自己使用

有关nginx的一些总结

首先看一下一般nginx管理的一些命令

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo apt-get install nginx
sudo /etc/init.d/nginx start #通过init.d下的启动文件启动
sudo service nginx start #通过ubuntu的服务管理器启动

ps -ef | grep nginx //查看nginx的进程
ps aux|grep nginx
kill -QUIT 主进程号 //关闭进程
/etc/init.d/nginx start //启动nginx
kill -INT master //关闭nginx

备份日志文件
mv log log2; //备份一个文件
Kill -USR1 `cat /xxx/path/log/nginx.pid`

nginx配置的一些意义

1
2
3
4
5
worker_processes 1; // 有1个工作的子进程,可以自行修改,但太大无益,因为要争夺CPU,一般设置为 CPU数*核数
Event {
// 一般是配置nginx连接的特性 如1个word能同时允许多少连接
worker_connections 1024; // 这是指 一个子进程最大允许连1024个连接
}

基于端口的虚拟主机配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

error_log /home/wwwlogs/nginx_error.log crit; //crit错误信息最少 debug错误信息最多 debug, info, notice, warn, error, crit
server {
listen 80; #监听端口
server_name a.com; #监听域名

location / {
root /var/www/a.com; #根目录定位
index index.html;
}
#正则表达式的localtion会覆盖掉 / 的匹配,所以图片会直接访问图片
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
root /home/www/var/www/image;
expires 30d;
}
}


response headers

Transfer-Encoding:chunked //内容是分块传输的

http 304 notModifed 文件还没有过期呢;nginx expires 30d;

1
2
3
4
5
6
7
8
location ~ [^/]\.php(/|$)
{
proxy_pass http://192.168.5.131:8080; //设置apache代理 反向代理
#try_files $uri =404;
#fastcgi_pass unix:/tmp/php-cgi.sock; //默认nginx处理
#fastcgi_index index.php;
#include fastcgi.conf;
}

./configure –prefix=/usr/local/fastphp –enable-fpm –with-mcrypt –enable-mbstring –disable-pdo –with-curl –disable-debug –disable-rpath –enable-inline-optimization –with-bz2 –with-zlib –enable-sockets –enable-sysvsem –enable-sysvshm –enable-pcntl –enable-mbregex –with-mhash –enable-zip –with-pcre-regex –with-mysql –with-mysqli –with-gd –with-jpeg-dir

文章目录
  1. 1. 有关nginx的一些总结
|