HTTP server Nginx configuration file details

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

This paper from


Configuration file Nginx nginx.conf server on this record, a partially annotated collection and network.

#Run user
user www-data;
#To start the process, usually set equal to the number and CPU
worker_processes 1;

#Global error log and the PID file
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;

#The work mode and the number of connections limit
events {
use epoll; #Epoll is multiplexed IO (I/O Multiplexing) in a way, but only for the linux2.6 kernel, can greatly improve the performance of nginx
worker_connections 1024;#Maximum concurrent link individual background worker process number of processes
# multi_accept on;
}

#Set the HTTP server, to provide load balancing support the use of reverse proxy it
http {
#Setting the MIME type, the type is defined by the mime.type file
include /etc/nginx/mime.types;
default_type application/octet-stream;
#Set log type
access_log /var/log/nginx/access.log;

#The sendfile directive specifies whether the nginx calls the sendfile function (zero copy) to the output file, for general application,
#Must be set to on, if used to download applications such as disk IO heavy load applications, can be set to off, to balance the disk and network I/O processing speed, reduce the system uptime.
sendfile on;
#tcp_nopush on;

#Connection timeout
#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;

#Open the gzip compression
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

#Set the request buffer
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

#Set the load balancing server list
upstream mysvr {
#The weigth parameter of value value, said the right; right; the higher the probability assigned more
#The Squid on this computer to open port 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 {
#Listening on port 80
listen 80;
#Defined using www.xx.com access
server_name www.xx.com;

#Set the access log of the virtual host
access_log logs/www.xx.com.access.log main;

#The default request
location / {
root /root; #The default web site root directory location defined server
index index.php index.html index.htm; #The definition of the index file name

fastcgi_pass www.xx.com;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

# The definition of error page
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /root;
}

#Static files, nginx processing
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
root /var/www/virtual/htdocs;
#30 days overdue, static files don't update, expired can set up a little, if frequent updates, you can set up a little.
expires 30d;
}
#PHP scripts request all forward to FastCGI processing. Using 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;
}
#Set the Nginx state.
location /NginxStatus {
stub_status on;
access_log on;
auth_basic "NginxStatus";
auth_basic_user_file conf/htpasswd;
}
#Prohibit access to the.Htxxx file
location ~ /\.ht {
deny all;
}

}
}

These are some of the basic configuration, the maximum benefits of the use of Nginx is load balancing

If you want to use load balancing, can modify the configuration of the HTTP node.:

#Set the HTTP server, to provide load balancing support the use of reverse proxy it
http {
#Setting the MIME type, the type is defined by the mime.type file
include /etc/nginx/mime.types;
default_type application/octet-stream;
#Set log type
access_log /var/log/nginx/access.log;

#Ellipsis as some configuration node

#. . . . . . . . . .

#Set the load balancing server list
upstream mysvr {
#The weigth parameter of value value, said the right; right; the higher the probability assigned more
server 192.168.8.1x:3128 weight=5;#The Squid on this computer to open port 3128
server 192.168.8.2x:80 weight=1;
server 192.168.8.3x:80 weight=6;
}

upstream mysvr2 {
#The weigth parameter of value value, said the right; right; the higher the probability assigned more

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

#The first virtual server
server {
#80 listening port 192.168.8.x
listen 80;
server_name 192.168.8.x;

#Load balancing requests to the ASPX suffix
location ~ .*\.aspx$ {

root /root; #The default web site root directory location defined server
index index.php index.html index.htm; #The definition of the index file name

proxy_pass http://mysvr ;#Request list server to the definition of mysvr

#The following are some configuration reverse proxy can be deleted.

proxy_redirect off;

#The back-end Web server users can access the real IP through X-Forwarded-For
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; #The largest single byte file allows a client to request number
client_body_buffer_size 128k; #The maximum byte buffer buffer proxy client request number,
proxy_connect_timeout 90; #Nginx and the back-end server connection timeout (proxy connection timeout)
proxy_send_timeout 90; #The back-end server data transmission time (agent send timeout)
proxy_read_timeout 90; #After a successful connection, the back-end server response time (agent receives a timeout)
proxy_buffer_size 4k; #Set the proxy server (nginx) to save the user head information buffer size
proxy_buffers 4 32k; #The proxy_buffers buffer, Webpage average in 32K the following words, this setting
proxy_busy_buffers_size 64k; #Under high load buffer size(proxy_buffers*2)
proxy_temp_file_write_size 64k; #Set the cache folder size, larger than the value, from the upstream server;

}

}
}


On the other, such as the need for the directory file automatic indexing can be added in the HTTP configuration

autoindex on;

To display all files in a directory, and the size and modify the time display will continue to add

location ~ ^/abc(/.*) {

autoindex_exact_size on;

autoindex_localtime on;

}

Note: the ^/abc nginx directory under html/abc directory

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Robert at December 22, 2013 - 7:38 PM