Nginx configuration file Configuration Items detailed description

Source: Internet
Author: User
Transferred from: http://www.cnblogs.com/xiaogangqq123/archive/2011/03/02/1969006.html

The following records the configuration file description of the Nginx server nginx.conf, and some of the comments are collected with the network.

#运行用户User Www-data;#启动进程, usually set to equal to the number of CPUsWorker_processes1;#全局错误日志及PID文件error_log/var/Log/nginx/Error.Log; pid/var/Run/nginx.pid;#工作模式及连接数上限events {use Epoll;One way in #epoll是多路复用IO (I/O multiplexing), but only for linux2.6 above the core, can greatly improve the performance of NginxWorker_connections1024x768;Maximum number of concurrent links #单个后台worker process processes# multi_accept on;}#设定http服务器, using its reverse proxy function to provide load balancing supportHTTP {#设定mime类型, the type is defined by the Mime.type fileInclude/etc/nginx/mime.types; Default_typeApplication/octet-stream;#设定日志格式access_log/var/Log/nginx/access.Log;#sendfile instruction Specifies whether Nginx calls the Sendfile function (zero copy mode) to output the file, for normal applications,#必须设为 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 system uptime.Sendfile on;#tcp_nopush on;#连接超时时间#keepalive_timeout 0;Keepalive_timeout $; Tcp_nodelay on;#开启gzip压缩Gzip on; Gzip_disable"MSIE [1-6]\. (?!. *SV1) ";#设定请求缓冲Client_header_buffer_size1K Large_client_header_buffers44K        include/etc/nginx/conf.d/*.conf; include/etc/nginx/sites-enabled/*;#设定负载均衡的服务器列表Upstream Mysvr {#weigth参数表示权值, the higher the weight, the greater the chance of being assigned.#本机上的Squid开启3128端口Server192.168. 8. 1:3128weight=5; Server192.168. 8. 2: theweight=1; Server192.168. 8. 3: theweight=6; } server {#侦听80端口Listen the;#定义使用www. xx.com Accessserver_name www.xx.com;#设定本虚拟主机的访问日志Access_log logs/www.xx.com.access.LogMain#默认请求Location/{root/root;#定义服务器的默认网站根目录位置Index index.php index.html index.htm;#定义首页索引文件的名称Fastcgi_pass www.xx.com;              Fastcgi_param script_filename $document _root/$fastcgi _script_name;            Include/etc/nginx/fastcgi_params; }# define Error prompt pageError_page -502503504/ -x.html; Location =/ -x.html {root/root; }#静态文件, Nginx handles it himself.Location ~ ^/(images|javascript|js|css|flash|media|static)/{root/var/www/virtual/htdocs;#过期30天, the static files are not updated, the expiration can be set a little larger, if updated frequently, you can set a smaller point. Expires -D }All #PHP script requests are forwarded to FASTCGI processing. Use the fastcgi default configuration.Location ~ \.php$ {root/root; Fastcgi_pass127.0. 0. 1:9000;            Fastcgi_index index.php;            Fastcgi_param Script_filename/home/www/www$fastcgi_script_name;        Include Fastcgi_params; }#设定查看Nginx状态的地址Location/nginxstatus {Stub_status on; Access_log on; Auth_basic"Nginxstatus";        Auth_basic_user_file conf/htpasswd; }#禁止访问. htxxx fileLocation ~/\.ht {deny all; }         }    }

The above is some basic configuration, the biggest advantage of using Nginx is load balancing

If you want to use load balancing, you can modify the configuration HTTP node as follows:

#设定http服务器, using its reverse proxy function to provide load balancing supportHTTP {#设定mime类型, the type is defined by the Mime.type fileInclude/etc/nginx/mime.types; Default_type Application/octet-stream;#设定日志格式Access_log/var/log/nginx/access.log;#省略上文有的一些配置节点# ..... #设定负载均衡的服务器列表Upstream Mysvr {#weigth参数表示权值, the higher the weight, the greater the chance of being assigned.Server192.168. 8. 1X:3128weight=5;#本机上的Squid开启3128端口Server192.168. 8. 2X: theweight=1;Server192.168. 8. 3X: theweight=6; } upstream MYSVR2 {#weigth参数表示权值, the higher the weight, the greater the chance of being assigned.Server192.168. 8. x: theweight=1;Server192.168. 8. x: theweight=6; }#第一个虚拟服务器Server{#侦听192.80 Port of 168.8.xListen the; server_name192.168. 8. x;#对aspx后缀的进行负载均衡请求Location ~. *\.aspx$ {root/root;#定义服务器的默认网站根目录位置IndexIndex. phpIndex. htmlIndex. htm;#定义首页索引文件的名称Proxy_pass http://mysvr; #请求转向mysvr defined list of servers#以下是一些反向代理的配置可删除.Proxy_redirect off;#后端的Web服务器可以通过X-forwarded-for Get the user real IPProxy_set_header Host $host;              Proxy_set_header X-real-ip $remote _addr;              Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for; Client_max_body_sizeTenM#允许客户端请求的最大单文件字节数Client_body_buffer_size -K#缓冲区代理缓冲用户端请求的最大字节数,Proxy_connect_timeout -;#nginx跟后端服务器连接超时时间 (proxy connection timed out)Proxy_send_timeout -;#后端服务器数据回传时间 (proxy send timeout)Proxy_read_timeout -;#连接成功后, back-end server response time (proxy receive timeout)Proxy_buffer_size4K#设置代理服务器 (nginx) buffer size for saving user header informationProxy_buffers4 +K#proxy_buffers缓冲区, the average page is below 32k, so setProxy_busy_buffers_size -K#高负荷下缓冲大小 (proxy_buffers*2)Proxy_temp_file_write_size -K#设定缓存文件夹大小, greater than this value, will be passed from the upstream server}         }    }

'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
  • '). Text (i)); }; $numbering. FadeIn (1700); }); });

    The above describes the Nginx configuration file configuration items detailed description, including aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.