nginx.conf
root html; 网站目录
core module : Main Events
Standard HTTP modules : Core Access FastCGI Gzip Log Proxy Rewrite Upstrem
通过官方查看模块帮助 http://nginx.org/en/docs/
.
├── client_body_temp
├── conf
│ ├── fastcgi.conf 动态配置
│ ├── fastcgi.conf.default
│ ├── fastcgi_params 参数
│ ├── fastcgi_params.default
│ ├── koi-utf
│ ├── koi-win
│ ├── mime.types
│ ├── mime.types.default
│ ├── nginx.conf 静态配置文件
│ ├── nginx.conf.default
│ ├── scgi_params
│ ├── scgi_params.default
│ ├── uwsgi_params
│ ├── uwsgi_params.default
│ └── win-utf
├── fastcgi_temp
├── html
│ ├── 50x.html 出错
│ └── index.html
├── logs
│ ├── access.log
│ ├── error.log
│ └── nginx.pid
├── proxy_temp
├── sbin
│ └── nginx
├── scgi_temp
└── uwsgi_temp
egrep -v "#|^$" nginx.conf | cat -n
1 worker_processes 1; 和CPU核心数相当 效率
2 events {
3 worker_connections 1024; worker 可以接受最大多少个链接
4 }
5 http {
6 include mime.types;
7 default_type application/octet-stream;
8 sendfile on;
9 keepalive_timeout 65;
10 server {
11 listen 80;
12 server_name localhost; 域名
13 location / {
14 root html;
15 index index.html index.htm;
16 }
17 error_page 500 502 503 504 /50x.html; 指定错误页面
18 location = /50x.html {
19 root html;
20 }
21 }
22 }
开始配置
server {
listen 80;
server_name www.hequan.com;
root html/www;
index index.html index.htm;
}
server {
listen 80;
server_name blog.hequan.com;
root html/blog;
index index.html index.htm;
}
/sbin/nginx -s reload
301跳转
server {
listen 80;
server_name hequan.com;
rewrite ^/(.*) http://www.hequan.com/$1 permanent;
}
解决恶意IP绑定
server {
listen 80;
location / {
deny all;
}
}
日志切割
cd /application/nginx/logs && \
/bin/mv www_access.log www_access_$(date +%F -d -1day).log
/application/nginx/sbin/nginx -s reload
crontab -e
00 00 * * * /bin/sh /application/nginx/logs/xx.sh >/dev/null 2&1
日志相关分析 awstats
200 正常 301 永久跳转 403 禁止访问 404 找不到请求的页面 500 内部服务器错误 502 坏的网关 503 服务当前不可用