Nginx basic configuration and parameters

Source: Internet
Author: User
This article describes nginx basic configuration and parameters. This article describes nginx basic configuration and parameters.

User nobody;

# 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 logs/error. log;

# Error_log logs/error. log notice;

# Error_log logs/error. log info;

# Pid logs/nginx. pid;

# Working mode and maximum number of connections

Events {

# Epoll is a method in Multiplexing I/O Multiplexing,

# It is only used for Linux and later kernels, which can greatly improve nginx performance

Use epoll;

# Maximum number of concurrent connections of a single backend worker process

Worker_connections 1024;

# The total number of concurrent jobs is the product of worker_processes and worker_connections.

# Max_clients = worker_processes * worker_connections

# Why max_clients = worker_processes * worker_connections/4 when reverse proxy is set

# Why should the reverse proxy be divided by 4? it should be an experience value.

# The maximum number of connections that the Nginx Server can handle under normal conditions is 4*8000 = 32000.

# The worker_connections value is related to the physical memory size.

# Because concurrency is subject to IO constraints, the max_clients value must be smaller than the maximum number of files that can be opened by the system

# The maximum number of files that can be opened by the system is proportional to the memory size. Generally, the number of files that can be opened on machines with 1 GB of memory is about 0.1 million.

# Let's take a look at the number of file handles that can be opened by VPS in MB memory:

# $ Cat/proc/sys/fs/file-max

# Output 34336

#32000 <34336, that is, the total number of concurrent connections is smaller than the total number of file handles that can be opened by the system, which is within the acceptable range of the operating system

# Therefore, the worker_connections value must be set based on the number of worker_processes processes and the maximum number of files that can be opened by the system.

# Make the total number of concurrent jobs smaller than the maximum number of files that can be opened by the operating system

# The essence is to configure the physical CPU and memory of the host.

# Of course, in theory, the total number of concurrent jobs may be different from the actual number, because there are other worker processes on the host that consume system resources.

# Ulimit-shn65535

}

Http {

# Set the mime type, which is defined by the mime. type file.

Include mime. types;

Default_type application/octet-stream;

# Set the log format

Log_format main '$ remote_addr-$ remote_user [$ time_local] "$ request "'

'$ Status $ body_bytes_sent "$ http_referer "'

'"$ Http_user_agent" "$ http_x_forwarded_for "';

Access_log logs/access. log main;

# 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 application disk I/O heavy load applications such as downloading, you can set it to off,

# To balance disk and network I/O processing speed and reduce 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].";

# Set request buffer

Client_header_buffer_size 128 k;

Large_client_header_buffers 4 128 k;

# Set VM configurations

Server {

# Listening to port 80

Listen 80;

# Define access using www.nginx.cn

Server_name www.nginx.cn;

# Define the default website root directory location of the server

Root html;

# Set access logs for the current virtual host

Access_log logs/nginx. access. log main;

# Default request

Location /{

# Define the name of the home index file

Index. php index.html index.htm;

}

# Define error prompt page

Error_page 500 502 503 x.html;

Location =/50x.html {

}

# Handle static files by nginx

Location ~ ^/(Images | javascript | js | css | flash | media | static )/{

# Static files are not updated for 30 days after expiration, and can be set to a larger value after expiration,

# If the update is frequent, you can set it to a smaller value.

Expires 30d;

}

# PHP script requests are all forwarded to FastCGI for processing. use the default FastCGI configuration.

Location ~ . Php $ {

Fastcgi_pass 127.0.0.1: 9000;

Fastcgi_index index. php;

Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;

Include fastcgi_params;

}

# Prohibit access to the. htxxx file

Location ~ /. Ht {

Deny all;

}

}

}

The above describes the basic configuration and parameters of nginx. For more information, see other related articles in the first PHP community!

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.