nginx入门

启动,停止和重新配置

./nginx   启动
./nginx -s stop  停止
./nginx -s
stop - 快速停止
quit - 正常停止
reload - 重新加载配置文件
reopen - 重新打开日志文件

配置文件的结构

nginx由配置文件中指定的指令控制的模块组成。
指令分为简单指令和块指令。
一个简单的指令由空格分隔的名称和参数组成,以分号(;)结尾。
块指令具有与简单指令相同的结构,但不是以分号结尾,而是以大括号({和})包围的一组附加指令结束。
如果块指令可以在大括号内部有其他指令,则称为上下文(例如: events, http, server和 location)。
配置文件中放置在任何上下文之外的伪指令都被认为是 主要的上下文。在events和http指令在主要上下文中,server 在http 中,location在 server 中。

符号后面 一行的其余部分被认为是一个注释。

服务静态内容

http 指令块包含以一个 server 块,server 块包含两个 location 块。

打开配置文件 注释掉所所有的 server 块,重新开始一个新的 server 块

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

    location /images/ {
        root /data;
    }
}

设置简单的代理服务器

server {
    listen 8080;
    root /data/up1;

    location / {
    }
}

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

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

设置FastCGI代理

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;
    }
}
posted @ 2017-09-01 18:33  Achxku  阅读(195)  评论(0编辑  收藏  举报