Second, Nginx server Basic Configuration command

Source: Internet
Author: User
Tags epoll sendfile nginx server

The default nginx server configuration file is stored in the installation directory Conf, and the master profile is named Nginx.conf.

The default nginx.conf in the/usr/local/nginx directory, the last compiler installation Nginx main configuration file is stored under/etc/nginx.

Install Compile: http://magine356wj.blog.51cto.com/2664956/1677064

Here are some comments about the nginx.conf

#################### #全局块 ############################################## #user nobody;          #使用的用户和组, the default is nobody, compile-time set to nginxworker_processes 1;       #指定工作进程数, there are usually a few CPUs used on the Nginx set corresponding digital #error_log logs/error.log; #可以使用 [Debug | info| notice| warn | error | crit] parameter #error_log logs/error.log notice; #error_log logs/error.log info; #pi       D Logs/nginx.pid;     #指定pid存放路径 ############### #events事件模块 ########################################## #events {worker_connections 1024;    Maximum number of connections per worker}##################### #http模块 ########################################## #http {#以下指令在http模块中生效    Include Mime.types;    Default_type Application/octet-stream;  #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;    #tcp_nopush on;  #keepalive_timeout0;    Keepalive_timeout 65;    #gzip on;        server {Listen 80;        server_name localhost;        #charset Koi8-r;        #access_log Logs/host.access.log Main;            Location/{root HTML;        Index index.html index.htm;        } #error_page 404/404.html;        # REDIRECT Server error pages to the static page/50x.html # Error_page 502 503 504/50x.html;        Location =/50x.html {root html; } # Proxy The PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ {# ProX        Y_pass http://127.0.0.1;        #} # Pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ {        # root HTML;        # Fastcgi_pass 127.0.0.1:9000;        # Fastcgi_index index.php;        # Fastcgi_param Script_filename/scripts$fastcgi_script_name; # include FASTCGI_params; #} # Deny access to. htaccess files, if Apache ' s document Root # concurs with Nginx ' s one # #l        ocation ~/\.ht {# deny all;       #}} # Another virtual host using mix of ip-, name-, and port-based configuration # #server {# listen    8000;    # Listen somename:8080;    # server_name somename alias Another.alias;    # location/{# root HTML;    # index index.html index.htm;    #} #} # HTTPS Server # #server {# listen 443 SSL;    # server_name localhost;    # ssl_certificate Cert.pem;    # Ssl_certificate_key Cert.key;    # Ssl_session_cache shared:ssl:1m;    # ssl_session_timeout 5m; # ssl_ciphers high:!anull:!    MD5;    # ssl_prefer_server_ciphers on;    # location/{# root HTML;    # index index.html index.htm; #    }    #}}

  The nginx.conf consists of three parts, the core (global), the events block, and the HTTP block. In an HTTP block, it also contains HTTP global blocks, multiple server blocks. Each server block also contains server global and multiple location1. A configuration block nested within the same configuration, with no order relationship between the individual.

First, Core:

The global block is a part of the default profile from the beginning to the events block, mainly to set some configuration directives that affect the overall operation of the Nginx server. The scope of these directives is the Nginx service global.
User syntax: User User[group] Default: Nobody nobody specifies the Nginx worker process to run users, default is nobody account Error_log syntax: Error_log file [Debug | info | noti Ce | Warn | Error | Crit]   default: ${prefix}/logs/error.log   set the location and level of error logs. PID   Syntax: PID file   process ID stores files. You can use Kill-hup Cat/var/log/nginx.pid/to reload the Nginx configuration file.     worker_processes   Syntax: worker_processes   Number Default value: 1   Specifies how many worker processes. Nginx can use multiple worker processes.

650) this.width=650; "title=" image "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; margin:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M01/70/0D/ Wkiol1wwhihicxtmaajizpw26zs322.jpg "width=" 899 "height=" 326 "/>

Change number to 3, and then perform PS Ax | With the exception of the master process, you can see that 3 worker processes have been generated.

II. Events Block

  The commands involved in the events block mainly affect the network connection between the Nginx server and the user. Use Epoll; #说明使用哪种事件模型, default is Epoll, can not be written. Worker_connections number; #主要用来设置允许每一个worker The maximum connections that the process is open at the same time. Clients = Worker_connections * work_process, set worker_connections according to the actual situation.

Third, HTTP module:

The instructions in the HTTP module include the introduction of the file, the Mime-type definition, the log definition, whether to use Sendfile transfer file, the connection timeout, the maximum number of single link requests, and so on.

650) this.width=650; "title=" image "style=" border-left-0px; border-right-width:0px; Background-image:none; border-bottom-width:0px; padding-top:0px; padding-left:0px; margin:0px; padding-right:0px; border-top-width:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M02/70/0D/ Wkiol1wwhigwkyfeaaejik0kkea937.jpg "width=" 641 "height=" 294 "/>

Include       mime.types;default_type  application/octet-stream; commonly used browsers can display a wide variety of files such as html,xml,gif and flash, media resources and so on. The browser distinguishes these resources by using the MIME Type. Default_type configures the MIME type used to handle front-end requests.
The Nginx server supports configuration of the service log format, size, output, etc. Access_log Specify the path log_format  Specify the log format specific parameters can be consulted: http://nginx.org/en/docs/http/ngx_http_log_module.html

Sendfile on | Off;   Turn sendfilekeepalive_timeout timeout on or off, which is 65s by default. Gzip on       Whether gzip compression is turned on, default disable

Four, server,location module

650) this.width=650; "title=" image "style=" border-top:0px; border-right:0px; Background-image:none; border-bottom:0px; padding-top:0px; padding-left:0px; margin:0px; border-left:0px; padding-right:0px "border=" 0 "alt=" image "src=" http://s3.51cto.com/wyfs02/M00/70/0D/wKioL1WwhIGQe8uxAACO5OeK_ Xo439.jpg "" 576 "height=" 207 "/>

Location [= | ~ | ~* | ^~] URI {...} =, requires the string and URI strictly match ~, with regular, case-sensitive ~*, with regular, not case-sensitive ^~, do not do pattern matching priority: The first is =, the second is ~;

Note: For HTTP modules, Server,location is only a minor annotation. Virtual host, rewrite and other functions, will be written in subsequent blog.

Second, Nginx server Basic Configuration command

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.