Linux self-study note--nginx Basic configuration

Source: Internet
Author: User

1. Basic Configuration

Worker_processes auto|3; Specifies the number of cores to use, the default auto, or the typical self-core number-1, which can be lscpu to view

Events {

Worker_connections 1024; Maximum concurrent connections, maximum concurrent responses worker_processes * Worker_connections

}

HTTP {

Keepalived_timeout 65 0 means no long connection

Keepalived_request Long Connection maximum number of resources, default 100

Keepalived_disable None|browser

server {

Listen 127.0.0.1:80 default_server default virtual host

server_name www.magedu.com

Match priority, exact-left match-right match-regular match

Www.magedu.com

*.magedu.com

Www.magedu.*

~^.*\.magedu\. *$


Root/usr/share/nginx/html

Location/{

}

match priority, exact-left match-regular match-without symbol

= Precise

^~ left Match

~ Regular match, case sensitive

~* regular match, case insensitive


Error_page 404/404.html;

location=/40x.html{

}

}

}

2. Status page

Location/status {

Stub_status;

}

Active connections Active Client link count

Accepts total number of client links received

Handled total number of client requests processed

Requests total number of requests

Total number of request-handled rejected

The number of Reading in the header of the Read client message

Writing number of response messages sent

Walting is in an idle connection waiting for the client to make a request, and the value may be

KeepAlive Timeout set too long

3. Prevent hotlinking

Location ~* \. (gif|jpg|png|bmp) $ {

Valid_referers None blocked *.magedu.com server_names ~\.google\. ~\.baidu\.;

if ($invalid _referer) {

return 403;

}

}

4.php-fpm

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;

}

5. Static and dynamic separation

Location/{

Proxy_pass http://192.168.1.11;

}

Location ~ \.php${

Proxy_pass http://192.168.1.12;

}

6. Load Balancing

Upstream Backend {

Server 192.168.1.11 weight=1;

Server 192.168.1.12 weight=1;

Ip_hash equivalent to SH | Least_conn minimum link;

Down Manually marking the Downline

Backup 192.168.1.13; Equivalent to sorry server

}

Location/{

Proxy_pass Http://backend;

}


Linux self-study note--nginx Basic configuration

Related Article

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.