发布日期:2019-11-21 16:05:40

nginx(读着: engine x)

 

1) nginx的官网文档《Beginer's Guide》 

这个指南大体讲了三个常用配置的例子:serving static content, setting up a simple proxy server; setting up fastCGI proxy server。

首先如何启动和停止nginx.

To start nginx, run the executable file. Once nginx is started, it can be controlled by invoking the executable with the -s parameter. Use the following syntax:

nginx -s signal
Where signal may be one of the following:

stop — fast shutdown
quit — graceful shutdown
reload — reloading the configuration file
reopen — reopening the log files

nginx的工作方式:一个master process和多个worker processes. master process主要用来读和校验configuration文件,以及维护worker processes. 具体的请求工作由worker processes处理。

nginx has one master process and several worker processes. The main purpose of the master process is to read and evaluate configuration, and maintain worker processes. Worker processes do actual processing of requests. nginx employs event-based model and OS-dependent mechanisms to efficiently distribute requests among worker processes. The number of worker processes is defined in the configuration file and may be fixed for a given configuration or automatically adjusted to the number of available CPU cores (see worker_processes).

nginx.conf 文件一般存放在 /usr/local/nginx/conf,   /etc/nginx 或者/usr/local/etc/nginx。

nginx.conf and placed in the directory /usr/local/nginx/conf, /etc/nginx, or /usr/local/etc/nginx.

查看nginx processes可以通过下面的命令。

ps -ax | grep nginx

 

1.1 配置一个static content server

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

    location /images/ {
        root /data;
    }
}
}

1.2 配置一个代理 (使用proxy_pass指令)

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

    location /images/ {
        root /data;
    }
}
}

被代理的server配置:

http{
server {
    listen 8080;
    root /data/up1;

    location / {
    }
}
}

 

1.3 配置一个fastCGI代理 (使用fastcgi_pass和fastcgi_param指令)

http{

server {
    location / {
        fastcgi_pass  localhost:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param QUERY_STRING    $query_string;
    }

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

}

ngx_http_core_module 中的指令含义可以参考 http://nginx.org/en/docs/http/ngx_http_core_module.html#root

发表评论