Record memo:
Nginx:
./Nginx-T check syntax
./Nginx-s reload Configuration
./Nginx-s stop
Fastcgi_param plus:
Fastcgi_param script_filename $ document_root $ fastcgi_script_name;
Nginx. conf plus:
Include site_enabled /*;
Put nginx configurations for each website in the site_enabled directory for convenient management
Example 1:
Server {
Listen 8090;
# SERVER_NAME www. domain1.xyz;
Root/opt/www/ka_oms;
Index index.html index. php;
Access_log off;
Location /{
Autoindex on;
Autoindex_exact_size off;
Autoindex_localtime on;
}
Location ~ \. Php $ {
Fastcgi_index index. php;
Fastcgi_pass 127.0.0.1: 9000;
Include fastcgi_params;
}
}
This example is to run the PHP website in combination with the php5-fpm and requires the following
Install PHP
Sudo apt-Get install PhP5 php5-cli php5-fpm php5-mysql
Php5-fpm:
Sudo service php5-fpm start
Sudo services php5-fpm stop
/Etc/PhP5/FPM/pool. d/www. conf listening mode, Performance Tuning
Example 2:
Server {
Listen 8085;
SERVER_NAME www. domain1.xyz;
Access_log off;
Location /{
Root/opt/www/th_cms;
Index default. aspx default. aspx;
Fastcgi_index default. aspx;
Fastcgi_pass 127.0.0.1: 9006;
Include/opt/APP/nginx/CONF/fastcgi_params;
}
}
In this example, run the. NET Website under mono and run the following
# Th_cms website
Fastcgi-mono-server4/applications =/:/opt/Th/www/th_cms // socket = TCP: 127.0.0.1: 9006 &
# Running user
User www-data;
# Start the process. Generally, it is set to be equal to the number of CPUs
Worker_processes 1;
# Global error logs and PID files
Error_log/var/log/nginx/error. log;
Pid/var/run/nginx. PID;
# Working mode and maximum number of connections
Events {
Use epoll; # epoll is a method of multiplexing io (I/O multiplexing), but it is only used for Linux and later kernels, which can greatly improve nginx performance.
Worker_connections 1024; # maximum number of concurrent connections of a single backend Worker Process
# Multi_accept on;
}
# Set the HTTP server and use its reverse proxy function to provide Load Balancing support
HTTP {
# Set the MIME type, which is defined by the mime. type file.
Include/etc/nginx/mime. types;
Default_type application/octet-stream;
# Set the log format
Access_log/var/log/nginx/access. log;
# The sendfile command specifies whether nginx calls the sendfile function (zero copy mode) to output files. For common applications,
# It must be set to on. If it is used for downloading and other application disk I/O heavy load applications, you can set it to off to balance the disk and network I/O processing speed and reduce the system uptime.
Sendfile on;
# Tcp_nopush on;
# Connection timeout
# Keepalive_timeout 0;
Keepalive_timeout 65;
Tcp_nodelay on;
# Enable gzip Compression
Gzip on;
Gzip_disable "MSIE [1-6] \. (?!. * Sv1 )";
# Set Request Buffer
Client_header_buffer_size 1 K;
Large_client_header_buffers 4 4 K;
Include/etc/nginx/CONF. d/*. conf;
Include/etc/nginx/sites-enabled /*;
# Set the Server list of Server Load balancer
Upstream mysvr {
# The weigth parameter indicates the weight. A higher weight indicates a higher probability of being assigned.
# Enable port 3128 for squid on the local machine
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 to port 80
Listen 80;
# Define access using www.xx.com
SERVER_NAME www.xx.com;
# Set access logs for the current virtual host
Access_log logs/www.xx.com. Access. Log main;
# Default request
Location /{
Root/root; # define the default website root directory location of the server
Index index. php index.html index.htm; # define the name of the home index file
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 500 502 503 x.html;
Location =/50x.html {
Root/root;
}
# Handle static files by nginx
Location ~ ^/(Images | JavaScript | JS | CSS | flash | media | static )/{
Root/var/www/virtual/htdocs;
# Static files are not updated for 30 days after they expire. You can set them to a larger value when they expire. If they are updated frequently, you can set them to a smaller value.
Expires 30d;
}
# PHP script requests are all forwarded to FastCGI for processing. Use the default FastCGI 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 address for viewing nginx status
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;
}
}
}
The above are some basic configurations. The biggest advantage of using nginx is load balancing.
To use Server Load balancer, you can modify and configure the HTTP node as follows:
# Set the HTTP server and use its reverse proxy function to provide Load Balancing support
HTTP {
# Set the MIME type, which is defined by the mime. type file.
Include/etc/nginx/mime. types;
Default_type application/octet-stream;
# Set the log format
Access_log/var/log/nginx/access. log;
# Omit some of the above configuration nodes
#..........
# Set the Server list of Server Load balancer
Upstream mysvr {
# The weigth parameter indicates the weight. A higher weight indicates a higher probability of being assigned.
Server 192.168.8.1x: 3128 Weight = 5; # enable port 3128 for squid on the local machine
Server 192.168.8.2x: 80 Weight = 1;
Server 192.168.8.3x: 80 Weight = 6;
}
Upstream mysvr2 {
# The weigth parameter indicates the weight. A higher weight indicates a higher probability of being assigned.
Server 192.168.8.x: 80 Weight = 1;
Server 192.168.8.x: 80 Weight = 6;
}
# First Virtual Server
Server {
# Listen to port 80 of 192.168.8.x
Listen 80;
SERVER_NAME 192.168.8.x;
# Load balancing requests with the aspx suffix
Location ~ . * \. Aspx $ {
Root/root; # define the default website root directory location of the server
Index index. php index.html index.htm; # define the name of the home index file
Proxy_pass http: // mysvr; # redirect requests to the list of servers defined by mysvr
# The following are some reverse proxy configurations that can be deleted.
Proxy_redirect off;
# The backend web server can use X-forwarded-for to obtain the user's real IP address.
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 10 m; # maximum number of bytes allowed for client requests per file
Client_body_buffer_size 128 K; # maximum number of bytes for the buffer proxy to buffer client requests,
Proxy_connect_timeout 90; # timeout for nginx connection to backend servers (proxy connection timeout)
Proxy_send_timeout 90; # backend server data return time (proxy sending timeout)
Proxy_read_timeout 90; # response time of the backend server after successful connection (proxy receiving timeout)
Proxy_buffer_size 4 K; # Set the buffer size for the proxy server (nginx) to save user header information
Proxy_buffers 4 32 K; # proxy_buffers buffer, if the average web page is below 32 K, this setting
Proxy_busy_buffers_size 64 K; # buffer size under high load (proxy_buffers * 2)
Proxy_temp_file_write_size 64 K; # sets the cache folder size. If it is greater than this value, it will be transmitted from the upstream Server
}
}
}