Nginx Server nginx.com configuration file detailed _nginx

Source: Internet
Author: User
Tags php script sendfile nginx server

This record describes the configuration file description for the Nginx server nginx.conf, with some comments collected with the network.

#运行用户 user www-data;
#启动进程, usually set to and the number of CPUs equal to worker_processes 1;
#全局错误日志及PID文件 Error_log/var/log/nginx/error.log;
Pid/var/run/nginx.pid; #工作模式及连接数上限 Events {use epoll; #epoll是多路复用IO (I/O multiplexing), but only for linux2.6 above the kernel, can greatly improve the performance of Nginx Worker_ 
Connections 1024 #单个后台worker The maximum number of concurrent links for process processes # multi_accept on; #设定http服务器, using its reverse proxy functionality to provide load balancing support for 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; The #sendfile instruction specifies whether Nginx calls the Sendfile function (zero copy) to output the file, #必须设为 on for general applications, or, if used for downloading applications disk IO Heavy load application, set to off to balance disk and network I/O processing speed,
Reduce the uptime of the system.
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参数表示权值, the higher the weight is the greater the chance of being assigned #本机上的Squid开启3128 Port 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 #定义使用www. xx.com Access server_name www.xx.com; #设定本虚拟主机的访问日志 access_log LOGS/WWW.XX.COM.ACCESS.L
OG 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; 
# define Error Prompt page Error_page 502 503 504/50x.html; Location =/50x.html {root/root} #静态文件, Nginx handle location ~ ^/(images|javascript|js|css|flash|media|static)/{root/v
Ar/www/virtual/htdocs;
#过期30天, the static file is not very updated, the expiration can be set larger, if frequently updated, you can set smaller.
Expires 30d; #PHP script requests are all 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_logOn
Auth_basic "Nginxstatus";
Auth_basic_user_file conf/htpasswd;
#禁止访问. htxxx file Location ~/\.ht {deny all;}} }

The above are 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 nodes as follows:

#设定http服务器, using its reverse proxy function to provide load balancing support for 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参数表示权值, the higher the number of weights assigned to the greater the 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 number of weights assigned to the greater the server 192.168.8.x:80 weight=1; server 192.168.8.x:80 weight=6;} #第一个虚拟服务 server {#侦听192.168.8.x 80 Port Listen server_name 192.168.8.x; #对aspx后缀的进行负载均衡请求 location ~. *\.aspx$ {root/root; #定 The default Web site root location of the semantic server index index.php index.html index.htm;
#定义首页索引文件的名称 Proxy_pass http://mysvr; #请求转向mysvr the list of servers defined #以下是一些反向代理的配置可删除.
Proxy_redirect off;
#后端的Web服务器可以通过X-forwarded-for obtains 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跟后端服务器连接超时时间 (Agent connection timeout) Proxy_send_timeout 90; #后端服务器数据回传时间 (Agent send timeout) proxy_read_timeout 90; #连接成功后, back-end server response time (proxy receive timeout) Proxy_buffer_size 4k; #设置代理服务器 (Nginx) to save the buffer size of user header information 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 upstream server}}}

The above is a small set to introduce the Nginx server nginx.com configuration file details, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.