Version Nginx
[Email protected] sbin]#./nginx-v
Nginx version:nginx/1.8.0
Configuration file nginx.conf
#user nobody; ---------------------------------define the user and user groups Nginx runs
Worker_processes 1; ---------------------------the number of nginx processes, the recommended setting is equal to the total CPU core number
#error_log Logs/error.log;
#error_log Logs/error.log Notice;
#error_log Logs/error.log Info; -------------Global error log, definition type [Debug | info | notice | warn | error | crit]
#pid Logs/nginx.pid; ----------------------Process Files
Events {----------------------------Working mode, maximum number of connections, #参考事件模型, use [kqueue | rtsig | epoll |/dev/poll | select | Poll]; The Epoll model is a high-performance network I/O model in the Linux version 2.6 kernel, and if it runs on FreeBSD, it uses the Kqueue model.
Worker_connections 1024; --------------------------------------#单个进程最大连接数 (maximum number of connections = number of connections * processes
}
HTTP {-------------------------#设定http服务器
Include Mime.types; --------------------------#文件扩展名与文件类型映射表
Default_type Application/octet-stream;---------------------#默认文件类型
#log_format Main ' $remote _addr-$remote _user [$time _local] "$request" ' Log format ....
# ' $status $body _bytes_sent ' $http _referer '
# ' "$http _user_agent" "$http _x_forwarded_for" ';
#access_log Logs/access.log Main;
Sendfile on;------------------------------------------#开启高效文件传输模式, the sendfile instruction specifies whether Nginx calls the Sendfile function to output the file, for the normal application is set to On, if used for downloading applications such as disk IO heavy load applications, can be set to off to balance disk and network I/O processing speed and reduce the load on the system. Note: If the picture does not appear normal, change this to off.
#tcp_nopush on; -----------#防止网络阻塞, #将HTTP响应头压缩到一个包中发送, can only be used when Sendfile is turned on
#keepalive_timeout 0;
Keepalive_timeout 65; #长连接超时时间, Unit is seconds
#gzip on; #开启gzip模块, require the installation of gzip to be specified when running./config
Upstream blog.ha97.com {
#upstream的负载均衡, weight is a weight that can be defined based on machine configuration. The Weigth parameter represents weights, and the higher the weight, the greater the probability of being allocated.
Server 192.168.80.121:80 weight=3;
Server 192.168.80.122:80 weight=2;
Server 192.168.80.123:80 weight=3;
}
server {------------------------------------------Setting up a virtual host
Listen 80; -------------------------------------------Listening Port
server_name localhost; -------------------------Domain # Domain name can have multiple, separated by a space
#charset koi8-r;
#access_log Logs/host.access.log Main;
Location/{----------------------------------#对 "/" Enable reverse Proxy
root HTML;
Index index.html index.htm;
}
#error_page 404/404.html;
# REDIRECT Server error pages to the static page/50x.html
#
Error_page 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;
#}
}
# Another virtual host using mix of ip-, name-, and port-based configuration
#
#server {
# Listen 8000;
# Listen somename:8080;
# server_name somename alias Another.alias;
# location/{
# root HTML;
# index index.html index.htm;
# }
#}
# HTTPS Server
#
#server {
# Listen 443 SSL;
# server_name localhost;
# ssl_certificate Cert.pem;
# Ssl_certificate_key Cert.key;
# Ssl_session_cache shared:ssl:1m;
# ssl_session_timeout 5m;
# ssl_ciphers high:!anull:! MD5;
# ssl_prefer_server_ciphers on;
# location/{
# root HTML;
# index index.html index.htm;
# }
#}
======================== Split Line ======================================================
Other modules for online summary
#设定http服务器
http
{
Include Mime.types; #文件扩展名与文件类型映射表
Default_type Application/octet-stream; #默认文件类型
#charset Utf-8; #默认编码
Server_names_hash_bucket_size 128; #服务器名字的hash表大小
Client_header_buffer_size 32k; #上传文件大小限制
Large_client_header_buffers 4 64k; #设定请求缓
Client_max_body_size 8m; #设定请求缓
Sendfile on; #开启高效文件传输模式, the sendfile instruction specifies whether Nginx calls the Sendfile function to output the file, and for normal applications to be set to ON, if it is used for downloading applications such as disk IO heavy load applications, can be off to balance disk and network I/O processing speed, Reduce the load on the system. Note: If the picture does not appear normal, change this to off.
AutoIndex on; #开启目录列表访问, the appropriate download server, the default shutdown.
Tcp_nopush on; #防止网络阻塞
Tcp_nodelay on; #防止网络阻塞
Keepalive_timeout 120; #长连接超时时间, Unit is seconds
#FastCGI相关参数是为了改善网站的性能: Reduce resource usage and improve access speed. The following parameters can be understood by literal means.
Fastcgi_connect_timeout 300;
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模块设置
gzip on; #开启gzip压缩输出
Gzip_min_length 1k; #最小压缩文件大小
Gzip_buffers 4 16k; #压缩缓冲区
Gzip_http_version 1.0; #压缩版本 (default 1.1, front End If squid2.5 please use 1.0)
Gzip_comp_level 2; #压缩等级
Gzip_types text/plain application/x-javascript text/css application/xml;
#压缩类型, the default is already included text/html, so there is no need to write, write up will not have a problem, but there will be a warn.
Gzip_vary on;
#limit_zone crawler $binary _remote_addr 10m; #开启限制IP连接数的时候需要使用
Upstream blog.ha97.com {
#upstream的负载均衡, weight is a weight that can be defined based on machine configuration. The Weigth parameter represents weights, and the higher the weight, the greater the probability of being allocated.
Server 192.168.80.121:80 weight=3;
Server 192.168.80.122:80 weight=2;
Server 192.168.80.123:80 weight=3;
}
#虚拟主机的配置
Server
{
#监听端口
Listen;
#域名可以有多个, separate
server_name www.ha97.com ha97.com with spaces;
Index index.html index.htm index.php;
Root/data/www/ha97;
Location ~. *\. (PHP|PHP5)? $
{
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
include fastcgi.conf;
}
#图片缓存时间设置
location ~. *\. ( GIF|JPG|JPEG|PNG|BMP|SWF) $
{
expires 10d;
}
#JS和CSS缓存时间设置
Location ~. *\. ( JS|CSS)? $
{
expires 1h;
}
#日志格式设定
Log_format access ' $remote _addr-$remote _user [$time _local] "$request" '
' $status $body _bytes_sent " $http _referer "'
'" $http _user_agent "$http _x_forwarded_for ';
#定义本虚拟主机的访问日志
Access_log/var/log/nginx/ha97access.log access;
#对 "/" Enable reverse proxy
Location/{
Proxy_pass http://127.0.0.1:88;
Proxy_redirect off;
Proxy_set_header x-real-ip $remote _addr;
#后端的Web服务器可以通过X-forwarded-for Get the user real IP
proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
#以下是一些反向代理的配置, optional.
Proxy_set_header Host $host;
Client_max_body_size 10m; #允许客户端请求的最大单文件字节数
Client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数,
Proxy_ Connect_timeout 90; #nginx跟后端服务器连接超时时间 (proxy connection timeout)
Proxy_send_timeout, #后端服务器数据回传时间 (proxy send timeout)
Proxy_read_timeout; #连接成功后, Back-end server response time (proxy receive timeout)
Proxy_buffer_size 4k; #设置代理服务器 (nginx) buffer size for saving user header information
proxy_buffers 4 32k; #proxy_buffers缓冲区, The average web page is set below 32k
Proxy_busy_buffers_size 64k; #高负荷下缓冲大小 (proxy_buffers*2)
Proxy_temp_file_write_size 64k;
#设定缓存文件夹大小, greater than this value, the
}
will be passed from the upstream server
#设定查看Nginx状态的地址
Location/nginxstatus {
Stub_status on;
Access_log on;
Auth_basic "Nginxstatus";
Auth_basic_user_file conf/htpasswd;
#htpasswd文件的内容可以用apache提供的htpasswd工具来产生.
}
#本地动静分离反向代理配置
#所有jsp的页面均交由tomcat或resin处理
location ~ .(jsp|jspx|do)?$ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8080;
}
#所有静态文件由nginx直接读取不经过tomcat或resin
location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$
{ expires 15d; }
location ~ .*.(js|css)?$
{ expires 1h; }
}
}
Understanding Nginx Configuration Files