user www www; #nginx调用的用户
worker_processes 8; #最大进程数
error_log /usr/local/nginx/logs/nginx_error.log crit; #错误日志位日志级别最少crit(debug, info, notice, warn, error,)
pid /usr/local/nginx/nginx.pid; #PID进程位置
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535; #允许打开最大文件数
events # events模块
{
use epoll; #自动适配你使用的系统I/0模型
worker_connections 65535; #工作进程的最大连接数量
}
http
{
include mime.types; #调用后缀识别模块
default_type application/octet-stream; # 默认文件类型
server_names_hash_bucket_size 128; #hash表大小
client_max_body_size 8m; #控制请求报文大小(就是上次限制啦)
sendfile on; #启动高效传输文件
tcp_nopush on; #启动数据包不会马上传送出去但是和tcp_nodelay冲突(这个是收到数据马上传送过去)
tcp_nodelay on; #禁用了Nagle 算法,也就是配合tcp_nopush选项
keepalive_timeout 60; #连接超时时间(注意:一般高并发配置为0)
fastcgi_connect_timeout 300; #fastcgi连接超时
fastcgi_send_timeout 300; #发送超时
fastcgi_read_timeout 300; #读取超时
fastcgi_buffer_size 64k; #缓冲大小
fastcgi_buffers 4 64k; #缓冲上限
fastcgi_busy_buffers_size 128k; #忙碌缓冲大小
fastcgi_temp_file_write_size 128k; #临时文件写入大小
gzip on; #开启压缩
gzip_min_length 1k; #最小长度
gzip_buffers 4 16k; #缓冲大小
gzip_http_version 1.0; #http版本
gzip_comp_level 2; #压缩等级
gzip_types text/plain application/x-javascript text/css application/xml; #匹配类型进行压缩
gzip_vary on; #预压缩
server
{
listen 80;
server_name test.test.com;
index index.html index.htm index.php;
root /home/www/test;
location /123/data.php{
if (!-e $request_filename) 是否为真(data.php文件是否存在)
{
rewrite ^/(.*)$ /123/data.php last; 匹配以/开头任何字符的数值,都重写到/123/data.php,并不在匹配
}
}
# location / {
# autoindex on; 开启目录浏览模式
# autoindex_exact_size on; 显示大小
# autoindex_localtime on; 显示时间
#}
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000; #反向代理PHP
fastcgi_index index.php;
include fcgi.conf; #引用的模板
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ #图片缓存时间
{
expires 30d;
}
location ~ .*\.(js|css)?$ #JS缓存时间
{
expires 1h;
worker_processes 8; #最大进程数
error_log /usr/local/nginx/logs/nginx_error.log crit; #错误日志位日志级别最少crit(debug, info, notice, warn, error,)
pid /usr/local/nginx/nginx.pid; #PID进程位置
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535; #允许打开最大文件数
events # events模块
{
use epoll; #自动适配你使用的系统I/0模型
worker_connections 65535; #工作进程的最大连接数量
}
http
{
include mime.types; #调用后缀识别模块
default_type application/octet-stream; # 默认文件类型
server_names_hash_bucket_size 128; #hash表大小
client_header_buffer_size 32k; #最大缓冲(请求大于指定的缓冲区,则使用
large_client_header_buffers分配更大的缓冲区)
large_client_header_buffers 4 32k; #最大缓冲client_max_body_size 8m; #控制请求报文大小(就是上次限制啦)
sendfile on; #启动高效传输文件
tcp_nopush on; #启动数据包不会马上传送出去但是和tcp_nodelay冲突(这个是收到数据马上传送过去)
tcp_nodelay on; #禁用了Nagle 算法,也就是配合tcp_nopush选项
keepalive_timeout 60; #连接超时时间(注意:一般高并发配置为0)
fastcgi_connect_timeout 300; #fastcgi连接超时
fastcgi_send_timeout 300; #发送超时
fastcgi_read_timeout 300; #读取超时
fastcgi_buffer_size 64k; #缓冲大小
fastcgi_buffers 4 64k; #缓冲上限
fastcgi_busy_buffers_size 128k; #忙碌缓冲大小
fastcgi_temp_file_write_size 128k; #临时文件写入大小
gzip on; #开启压缩
gzip_min_length 1k; #最小长度
gzip_buffers 4 16k; #缓冲大小
gzip_http_version 1.0; #http版本
gzip_comp_level 2; #压缩等级
gzip_types text/plain application/x-javascript text/css application/xml; #匹配类型进行压缩
gzip_vary on; #预压缩
server
{
listen 80;
server_name test.test.com;
index index.html index.htm index.php;
root /home/www/test;
location /123/data.php{
if (!-e $request_filename) 是否为真(data.php文件是否存在)
{
rewrite ^/(.*)$ /123/data.php last; 匹配以/开头任何字符的数值,都重写到/123/data.php,并不在匹配
}
}
# location / {
# autoindex on; 开启目录浏览模式
# autoindex_exact_size on; 显示大小
# autoindex_localtime on; 显示时间
#}
location ~ .*\.(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000; #反向代理PHP
fastcgi_index index.php;
include fcgi.conf; #引用的模板
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ #图片缓存时间
{
expires 30d;
}
location ~ .*\.(js|css)?$ #JS缓存时间
{
expires 1h;
}
nginx负载均衡
upstream backserver {
server 192.168.0.14 weight=3; 权重越高,在被访问的概率越大,如上例,分别是30%,70%。
server 192.168.0.15 weight=7;
#fair; 根据响应时间
}
基本先补充到此,有新的问题可以发表补上