tengine的配置文件 ../tengine/conf/nginx.conf,根据系统需求及服务器配置设置其中部分参数。
打开配置文件,vi nginx.conf
#设置nginx用户和组,windows下不指定
#user nobody;
#设定nginx对外提供web服务时的worker进程数,一般等于或2倍于CPU数量
worker_processes 4;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
#events模块中包含nginx中所有处理连接的设置
events {
#设置可由一个worker进程同时打开的最大连接数,其值由系统的可用socket连接数限制(~64K)
worker_connections 2048;
#使用网络IO模型linux建议epoll,windows下不指定
use epoll;
}
#HTTP模块控制着nginx http处理的所有核心特性
http {
include mime.types;
default_type application/octet-stream;
#定义日志格式
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 logs/access.log main;
sendfile on;
#tcp_nopush on;
#给客户端分配keep alive链接超时时间,设置低些可以让ngnix持续工作的时间更长。
#keepalive_timeout 0;
keepalive_timeout 65;
#设置上传文件最大值
client_max_body_size 8M;
#开启后则nginx采用gzip压缩的形式发送数据,这会减少发送的数据量
gzip on;
#负载均衡设置,XXXX1和XXXX2两个不同的server
upstream XXXX1 {
server IP:端口;
#ip_hash;
}
upstream XXXX2 {
server IP:端口;
#ip_hash;
}
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://XXXX1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
index index.html index.jsp login.jsp index.htm;
#root html;
#index index.html index.htm;
}
location / {
proxy_pass http://XXXX2;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
index index.html index.jsp login.jsp index.htm;
}
#设置静态文件夹static的访问路径(绝对路径)
location ^~ /static/ {
root /data/tengine/web;
expires 7d;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
...
...
}
这里我仅设置了工作中用到的部分参数,static静态文件(就是那些css,js文件)的存放路径要设置正确,上篇提到我把tengine安装在数据盘/data目录下,所以这里我设置的路径是“/data/tengine/web”,最后一定要注意防火墙配置,检查是否开启相应端口。