Home  >  Article  >  Backend Development  >  Nginx.conf configuration summary

Nginx.conf configuration summary

WBOY
WBOYOriginal
2016-08-08 09:30:47953browse

The projects in recent months have all been built in the nginx environment. I hereby record the relevant content of the configuration file in case of emergency. Welcome to complain~~

Please check the official website diligently for detailed configuration information Document: http://wiki.nginx.org/Configuration

#Specify the user and user group for Nginx to run. Based on this, you can set the permissions for nginx to access the folder to prevent illegal users from accessing folders without permissions. By the way, for the log file reading and writing of the php project

#, the user is not nginx, because nginx forwards php to php-cgi for analysis, so the user is the owner of php-cgi, usually www-data

user nginx nginx;

#The number of processes to start nginx should be less than or equal to the total number of CPU cores to improve the concurrency of the program

worker_processes 4;

#global Access and error logs and their levels, [ debug | info | notice | warn | error | crit ]

access_log /var/nginx/access.log;

error_log /var/nginx/error.log warn;

#Default log format setting

log_format access $remote_addr - $remote_user [$time_local] "$request" '

'$status $body_bytes_sent "$http_referer" '

'"$http_user_agent" $http_x_forwarded_for';


#File when the process is running

pid /run/nginx.pid;

#Working mode and maximum number of connections

events

{

# Event model, use [ kqueue | rtsig | epoll | /dev/poll | select | poll ]; Performance network I/O model, if running on FreeBSD, use the kqueue model.

use epoll;

#The maximum number of connections for a single process (maximum number of connections = number of connections * number of processes), my configuration is 768*4

worker_connections 768;

#Enable simultaneous Accept multiple requests, high concurrency

multi_accept on;

}

#Set http server

http

{

include mime .types; #Use MIME format, file extension and file type mapping table

default_type application/octet-stream; #Default file type, file stream

#charset utf-8; #Default encoding

server_names_hash_bucket_size 128; #Hash table size of server name

#Set the upper limit of upload file size to 8MB

client_max_body_size 8m;

#Enable efficient file transfer mode, Call sendfile function (zero copy mode) to output files , set to on for ordinary applications, if used for disk IO heavy load applications such as downloading, #can be set to off to balance disk and network I/O processing speed, reduce system load and

uptime. Note: If the picture does not display properly, change this to off. sendfile on;

#Set access black and white list, file name, size

white_black_list_conf conf/white.list zone=white1:4m;

white_black_list_conf conf/black. list zone =black1:4m; white_list white1 on; #Whitelist white1 is turned on in the entire http{}
black_list black1 on; #Blacklist black1 is turned on in the entire http{}

tcp_nopush on; #Prevent Network blockingtcp_nodelay on; #Prevent network blocking

keepalive_timeout 65; #Long connection timeout, in seconds

#Turn on gzip, GNU compress static resources, optimize website access speed

gzip on;

#Turn on gzip compression output

gzip_min_length 1k; #Turn on the minimum file size limit for compression

gzip_buffers 4 16k; # Set up the system to get several units of cache Used to store gzip compression result data stream, apply for 4*16=64k cache at a time

gzip_http_version 1.0; #Compress files using http1.0 and above

gzip_comp_level 2; #Compression level , 1-10, the larger the value, the higher the compression rate

#Compressed file types, css, js, php, jpg, png

gzip_types

text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png

gzip_vary on;#Allow exceptions

gzip_disable"MISE[1-6]"#Disable compression for IE6 and below

#limit_zone crawler $binary_remote_addr 10m; #Need to use when turning on limiting the number of IP connections

upstream www .xxx.com {

#upstream load balancing, weight is the weight, and the weight can be defined according to the machine configuration. The weigth parameter represents the weight. The higher the weight, the greater the probability of being assigned.

server 192.168.80.121:80 weight=3;

server 192.168.80.122:80 weight=2;

}

#FastCGI related parameters are to improve the performance of the website: reduce resource usage and increase access speed.

fastcgi_connect_timeout 300;

fastcgi_send_timeout 300;

fastcgi_read_timeout 300;

fastcgi_buffer_size 64k;

fastcgi_buffers 4 64k;

fastcgi_busy_buffers_size 128k;

fastcgi_temp_file_write_size 128k;

#Configuration of each server

server

{

#Default listening http 80 port, both ipv4 & ipv6

listen 80;

listen [: :]:80 default_server ipv6only=on;


#You can have multiple domain names, separated by spaces

server_name www.xx.com xx.com;

index index.php;

root /data/www/xx;

#The mobile phone leads to another page

location / {

#Determine the access terminal type

if ($http_user_agent ~* '(Android| iphone | ipad | webos | ipod | BlackBerry) ') { rwrite ^.+ http://m.xx.com; } root/usr/share/nginx/html; l index .html; |jpg|
jpeg|png|bmp|swf
)$ {




expires 10d;                                                                                                                   

#phpguide9000 Port

location ~ .php$ {                                                                                                                                                                                                          ​              # NOTE: You should have "cgi .fix_pathinfo = 0;" in php.ini                                                                                                                       ​ ​ ​ #fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; S and CSS cache time settings


location ~ .*.(js|css)?$

{

expires 1h;



}




#Error page
error_page 500 502 503 504 /50x.html;
location = /50x.html {
                root /usr/share/nginx/ html;
        }


#Enable reverse proxy for "/"

location / {

proxy_pass http://127.0.0.1:88;

proxy_redirect off;

proxy_set_header Reverse proxy configuration, optional.

proxy_set_header Host $host;


client_max_body_size 10m; #The maximum number of bytes of a single file allowed to be requested by the client


client_body_buffer_size 128k; #The maximum number of bytes that the buffer proxy buffers the client request,

proxy_connect_timeout 90; #nginx connection timeout with backend server (proxy connection timeout)

proxy_send_timeout 90; #Backend server data return time (proxy send timeout)

proxy_read_timeout 90; #After successful connection, backend server response time (proxy receive timeout)

proxy_buffer_size 4k; #Set proxy The buffer size used by the server (nginx) to save user header information

proxy_buffers 4 32k; #proxy_buffers buffer, the average web page setting is below 32k

proxy_busy_buffers_size 64k; #Buffer size under high load (proxy_buffers*2) TProxy_temp_file_write_size 64K;

#Set the cache folder size, greater than this value, will pass from the upstream server

}

# /NginxStatus {

stub_status on;

access_log on;

auth_basic "NginxStatus";

auth_basic_user_file confpasswd;

#htpasswd file content can be retrieved using the htpasswd tool provided by apache produce.

}

#If you use j2ee, the page can be directed to port 8080,

All

jsp pages are processed by tomcat or resin

location ~ .(jsp | jspx|do|action)?$ {proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header

proxy_pass http : //127.0.0.1: 8080;

}}} #Then set a mobile access to Server, take the request from the mobile phone to the main station

server { Listen 80; server_name m.xx.com www.m.xx.com;

access_log /usr/share/nginx/logs/mobile_access.log; error_log /usr/share/nginx/logs/mobile_error.log;

location / { ~ root /usr/share/nginx/ html/mobile;}}

local ~ .php $ {

root/usr/share/nginx/html/mobile; OULD HAVE " cgi.fix_pathinfo = 0;" in php.ini

                                                                                                                           ​ ​ ​ #fastcgi_pass unix:/var/run/php5-fpm.sock;

              fastcgi_index index.php;

            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                                ’             ’ s         through ’'s'  ‐  ‐‐‐‐‐‐ fastcgi_index.


}



The above introduces the Nginx.conf configuration summary, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn