# nginx运行的用户名
user nginx;
# nginx启动进程,通常设置成和cpu的数量相等,这里为自动
worker_processes auto;
# errorlog文件位置
error_log /usr/local/nginx/logs/error.log;
# pid文件地址,记录了nginx的pid,方便进程管理
pid /usr/local/nginx/logs/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
# 用来加载其他动态模块的配置
include /usr/local/nginx/conf/vhost/*.conf;
# 工作模式和连接数上限
events {
# 每个worker_processes的最大并发链接数
# 并发总数:worker_processes*worker_connections
worker_connections 1024;
}
# 与提供http服务相关的一些配置参数类似的还有mail
http {
# 设置日志的格式
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
# access_log记录访问的用户、页面、浏览器、ip和其他的访问信息
access_log /usr/local/nginx/logs/access.log main;
# 这部分下面会单独解释
# 设置nginx是否使用sendfile函数输出文件
sendfile on;
# 数据包最大时发包(使用Nagle算法)
tcp_nopush on;
# 立刻发送数据包(禁用Nagle算法)
tcp_nodelay on;
# 链接超时时间
keepalive_timeout 65;
# 这个我也不清楚...
types_hash_max_size 2048;
# 引入文件扩展名与文件类型映射表
include /usr/local/nginx/conf/mime.types;
# 默认文件类型
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /usr/local/nginx/conf/vhost/*.conf;
}
server{
listen 80;
server_name www.blog.com;
root /var/www/blog/public;
index index.html index.htm index.php;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}