03 Dec 2015
worker_processes 2; ## 设置为cpu的数目,Default: 1(1.3.8和1.2.5之后可以设置为auto) # cat /proc/cpuinfo |grep -E "processor|physical id|core id" processor : 0 physical id : 0 core id : 0 processor : 1 physical id : 2 core id : 0 ## 我们拥有两个逻辑核心(2个物理cpu,每个cpu有1个内核),所以需要配置此项为2,而且我们还需要配置worker_cpu_affinity,与这个配置项配合 ## 此配置最多开8个,多了就不会带来性能提升了 worker_cpu_affinity 0101 1010; ## 绑定第一个进程到cpu1,第二个进程到cpu2 error_log /web/log/error.log error; ## 指定error_log的位置,默认是error_log logs/error.log error; ## events块 events { use epoll; worker_connections 1024; } ## total connections equal worker_processes * worker_connections ## epoll模式是nginx高性能的重点 ## httpd块(包含server块) log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; ## uncomment log_format keepalive_timeout 65; ## 连接维持时间 include /data/server/nginx/conf/vhost/*.conf; ## 指定vhost配置文件路径
listen 80; ## 监听端口 ## listen 端口 default_server; 后面加上default_server的含义是指,如果无法匹配任何server块时,默认把request发到这里处理 ## 可以listen多个不同端口 # 例如同时listen http和https # *************** # listen 80; # listen 443 ssl; # *************** # 注意不能增加ssl on,否则会使普通的http访问失效 server_name localhost; ## 主机名 access_log logs/host.access.log main; ## 开启访问日志 root /data/web; ## server 块的默认家目录 location / { index index.html index.htm; } ## 针对家目录做的设置
vi /usr/local/nginx/conf/nginx.conf
*******************************************
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
## "/usr/local/nginx/html"是网站目录路径
*******************************************
## 解析php文件
# fastcgi_pass 后面可跟
# ip和端口
127.0.0.1:9000
# 也可跟unix文件
fastcgi_pass unix:/tmp/php-cgi.sock
# 具体跟什么格式,需要看php-fpm.conf中配置的listen项来确定
# 当location中有root的时候,会优先生效,而不是采用server块的root配置
# fastcgi_param配置的是传入fastcgi server的参数,SCRIPT_FILENAME指定传入脚本所在的位置,后面跟脚本所在root目录,$fastcgi_script_name是脚本名称
# nginx configuration file structure
https://www.digitalocean.com/community/tutorials/understanding-the-nginx-configuration-file-structure-and-configuration-contexts