[Personal Notes] along with the official documentation to learn nginx - Beginner's Guide

Foreword

About installation and nginx, I was watching the video, lack of knowledge of make, make install other compiler command, so I will talk about, and highly recommend everyone to go look at the video say what nginx is, what can you do, write it down, Let's look at the official documentation to learn how to use.

So here passing installation and introduction, ready virtual machine, and official documents http://nginx.org/en/docs/ simultaneously learn it!

First try the server can not run up and start nginx

Access unexpectedly reported a 403, but could see nginx has been launched, the solution: https: //www.cnblogs.com/haon/p/10959934.html, non-403 error trying to close what firewall

 The following black word document my personal translator, I learned to understand the document labeled as red , italics  independent representatives of the document content

Start

This document is divided into four sections, the last one before I do not read

  • nginx semaphore command
  • nginx.conf file structure
  • How to deal with static resources
  • Do a simple proxy server
  • Make a FastCGI agent (this stuff?)

A semaphore command

Java thread familiar friends should have heard the Semaphore class (I do not know is just about done with thread communication?), Are not familiar with it does not matter, just remember the beginning here and enter the word S (line) like the communication process It helps to remember this command.

Command so long

Four signal optional

  • Quick stop close
  • quit different from the stop off, the request will be processed first and then off
  • reload reload configuration file
  • reopen rewrite the log file

ex:nginx -s stop 

Detailed documentation only speak reload this command (pre-knowledge you need to know nginx is a master process and multiple worker processes composition), will test and application configuration files master process receives the reload command, if validated, start a new the worker process, notify the worker originally closed and smooth transfer request, otherwise, master rollback process will continue to use the old configuration, and notifies the old worker to stop accepting new requests and completes the current close all connections

master process and worker processes, hereinafter referred to as the main thread and a worker thread

I have these two processes are too literally, the main thread should be responsible for receiving the request, the worker thread is responsible for handling requests, as in SocketServer, when the accept () after a request to the thread pool. Of course, the reality is not so, nginx can handle high concurrent requests thanks to AIO model, of course, my example here but I guess the status of the two processes.

On how to roll back, there is no mention, do not know and kill -usr2 the same principle.

Two, nginx.conf configuration file

I can speak and watch a video installation about the same share to you

ex: instruction block {

XXXXX instruction;

XXXXX instruction;

}

It describes the main block of four, meaning I need to look at Baidu

  • events  management connection configuration
  • HTTP  HTTP Server Configuration
  • server  virtual server configuration, you might see behind me to understand
  • LOCATION  URI of the path match

This code block is four nesting relationship, events and http code block is the top, where at http server, location in the server, the configuration is as follows

 

 Third, the process static requests

 Here is a combination of knowledge of some of the above configuration of the above, the instruction to be a demo application, do what I do on the line, here we use a new command

root: location is responsible for matching the request path, where location is the priority longest match strategy, root is the home directory of nginx real folder path

ex:

server {
    location / {
        root /data/www;
    }

    location /images/ {
        root /data;
    }
}

如果URL是/images/1.jpg,那么真实文件得在 安装目录/data/images/1.jpg 才不会报404

我写的时候遇到一个小问题,以为指令块要用分号结尾,指令才需要分号,reload命令的时候,报错了,改完再reload没问题。

 

四、设置简单代理服务器

这里大概讲了三个东西

1、root指令也可以写在server下,功能一样

ex:

server {
    listen 8080;
    root /data/up1;

    location / {
    }
}

2、proxy_pass 指令,配置代理

ex:

server {
    location / {
        proxy_pass http://localhost:8080;
    }

    location /images/ {
        root /data;
    }
}

3、location 接正则表达式

ex:

location ~ \.(gif|jpg|png)$ {
    root /data/images;
}

五、配置FastCGI代理,用不着,先不看



Guess you like

Origin www.cnblogs.com/haon/p/10961838.html