Configuration file description for Nginx server nginxconf

Source: Internet
Author: User
Tags sendfile nginx server
In this record the Nginx server nginx.conf configuration file description, some comments collected with the network.

Run user

User Www-data;

Start process, usually set to equal to the number of CPUs

Worker_processes 1;

Global error log and PID file

Error_log/var/log/nginx/error.log;
Pid/var/run/nginx.pid;

Operating mode and maximum number of connections

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 Nginx
Worker_connections; Maximum number of concurrent links #单个后台worker process processes
# multi_accept on;
}

Set up an HTTP server to provide load balancing support with its reverse proxy function

HTTP {
#设定mime类型, the type is defined by the Mime.type file
Include/etc/nginx/mime.types;
Default_type Application/octet-stream;
#设定日志格式
Access_log/var/log/nginx/access.log;

#sendfile 指令指定 nginx 是否调用 sendfile 函数(zero copy 方式)来输出文件,对于普通应用,#必须设为 on,如果用来进行下载等应用磁盘IO重负载应用,可设置为 off,以平衡磁盘与网络I/O处理速度,降低系统的uptime.sendfile        on;#tcp_nopush     on;#连接超时时间#keepalive_timeout  0;keepalive_timeout  65;tcp_nodelay        on;#开启gzip压缩gzip  on;gzip_disable "MSIE [1-6]\.(?!.*SV1)";#设定请求缓冲client_header_buffer_size    1k;large_client_header_buffers  4 4k;include /etc/nginx/conf.d/*.conf;include /etc/nginx/sites-enabled/*;#设定负载均衡的服务器列表 upstream mysvr {#weigth参数表示权值,权值越高被分配到的几率越大#本机上的Squid开启3128端口server 192.168.8.1:3128 weight=5;server 192.168.8.2:80  weight=1;server 192.168.8.3:80  weight=6;}

server {
#侦听80端口
Listen 80;
#定义使用www. xx.com Access
server_name www.xx.com;

    #设定本虚拟主机的访问日志 access_log Logs/www.xx.com.access.log main; #默认请求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;      }# Definition error page error_page 502 503 504/50x.html; Location =/50x.html {root/root;}    #静态文件, Nginx processing 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 30d;} All #PHP script requests are forwarded to fastcgi processing.    Use the fastcgi default configuration. Location ~ \.php$ {root/root;    Fastcgi_pass 127.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 file Location-/\.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:

Set up an HTTP server to provide load balancing support with its reverse proxy function

HTTP {
#设定mime类型, the type is defined by the Mime.type file
Include/etc/nginx/mime.types;
Default_type Application/octet-stream;
#设定日志格式
Access_log/var/log/nginx/access.log;

#省略上文有的一些配置节点#。。。。。。。。。。#设定负载均衡的服务器列表 upstream mysvr {#weigth参数表示权值,权值越高被分配到的几率越大server 192.168.8.1x:3128 weight=5;#本机上的Squid开启3128端口server 192.168.8.2x:80  weight=1;server 192.168.8.3x:80  weight=6;}

Upstream MYSVR2 {
#weigth参数表示权值, the higher the weight, the greater the chance of being assigned.

server 192.168.8.x:80  weight=1;server 192.168.8.x:80  weight=6;}

#第一个虚拟服务器
server {
#侦听192.80 Port of 168.8.x
Listen 80;
server_name 192.168.8.x;

  #对aspx后缀的进行负载均衡请求location ~. *\.aspx$ {root/root;   #定义服务器的默认网站根目录位置 index index.php index.html index.htm;      #定义首页索引文件的名称 Proxy_pass http://mysvr; #请求转向mysvr the server list #以下是一些反向代理的配置可删除 defined.      Proxy_redirect off;      #后端的Web服务器可以通过X-forwarded-for Get the user real IP proxy_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_size 10m;  #允许客户端请求的最大单文件字节数 client_body_buffer_size 128k;  #缓冲区代理缓冲用户端请求的最大字节数, Proxy_connect_timeout 90;        #nginx跟后端服务器连接超时时间 (proxy connection timeout) Proxy_send_timeout 90;         #后端服务器数据回传时间 (proxy send timeout) proxy_read_timeout 90;             #连接成功后, back-end server response time (proxy receive timeout) Proxy_buffer_size 4k;               #设置代理服务器 (Nginx) Save the user header information buffer size Proxy_buffers 4 32k;    #proxy_buffers缓冲区, the average page below 32k, so set proxy_busy_buffers_size 64k;  #高负荷下缓冲大小 (proxy_buffers*2) proxy_temp_file_write_size 64k; #设定缓存文件夹大小, greater than this value, will be passed from the upstream server}}

}

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

  • Related Article

    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.