Practical nginx Reading Notes-nginx configuration file

Source: Internet
Author: User
Tags sendfile

Let's take a look at the next nginx configuration.

# User nobody Nobody; # worker_processes 4; # Number of worker processes, which is generally equal to the number of CPU cores or twice the total number of workers # error_log logs/error. log; # Storage path of error logs Error Log levels include [debug | info | notice | error | warn | crit] # error_log logs/error. log notice; # error_log logs/error. log Info; # PID logs/nginx. PID; # specify the path events {use epoll; # epoll freebbd recommended for Linux worker_connections 1024; # maximum number of connections (maximum number of connections = number of connections * Number of processes)} HTTP {include mime. types; # default_type application/octet-stream; # default file type # 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; sendfile on; # enable the efficient file transmission mode. The sendfile command specifies whether nginx calls the sendfile function to output files,
For general applications that are set to on, if 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 load. Note: If the image is not displayed properly, change it to off. # Tcp_nopush on; # keepalive_timeout 0; keepalive_timeout 65; # long connection timeout time in seconds gzip on; # enable gizp compression gzip_min_length 1 K; gzip_buffers 4 16 K; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/X-JavaScript text/CSS application/XML; # compressed file type # current nginx configuration server {Listen 80; # Listening to port 80, can be changed to other ports SERVER_NAME 192.168.0.4; ############# current service domain name # charset koi8-r; # access_log logs/host. access. log main; Location/{root HTML; index index.html index.htm ;}}


The nginx configuration file structure is

......

Events

{

.....................

}

HTTP

{

Server {}

Server {}

}

IP address-based configuration for nginx Virtual Host Configuration
Server {Listen 192.168.0.1: 80; SERVER_NAME 192.168.0.1 location/{root html1; # root directory index index.html index.htm; # response page }}# second virtual host server {Listen 192.168.0.2: 80; # listening port and IP # Listen somename: 8080; SERVER_NAME 192.168.0.2; # host name location/{root html2; index index.html index.htm ;}}
Domain name-Based Configuration
Server {Listen 80; SERVER_NAME www.a.com; Location/{root html1; # root directory index index.html index.htm; # response page }}# second VM server {Listen 80; SERVER_NAME www. B .com; location/{root html2; index index.html index.htm ;}}
Port-Based Configuration
Server {Listen 80; SERVER_NAME 192.168.0.1; Location/{root html1; # root directory index index.html index.htm; # response page }}# second virtual host server {Listen 81; SERVER_NAME 192.168.0.1; location/{root html2;
Autoindex on; # list the file Directory Index index.html index.htm ;}}


 

 

Practical nginx Reading Notes-nginx configuration file

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.