nginx初学者指南

http://nginx.org/en/docs/beginners_guide.html

nginx启动后,有一个master进程和几个worker进程,真正响应用户的是worker进程

nginx用的比较多的有两个主要功能,作为web服务器响应静态资源请求和作为代理服务器转发请求,安装配置非常简单,以致于我都懒得写。配置上这里只写几个注意点:

  1. 默认的静态资源放在 {$nginx_home}/html目录下

   2.默认的nginx的配置文件是nginx.conf,在{$nginx_home}/conf目录下

   3. 一个简单的响应配置,以下内容配置在nginx.conf 中

server {
  listen 80;   //监听80端口
  server_name localhost;

  location / {     //location 后面的路径就是要响应的路径前缀
    root html;    //响应的本地目录
    index index.html index.htm;
  }
}

 4. 当配置多个location时,响应的优先级

     如果路径前缀用的是正则表达式,则优先级最高 

                    示例 :

         location ~ .(gif|jpg|png)$    //正则式应以~符号开头,这个例子表示匹配以.git、.jpg或.png结尾的路径

     路径前缀长的优先级较高

     最终就是  /这个路径前缀了

 5. nginx的启动、关闭、重启

  • nginx -s stop — fast shutdown
  • nginx -s quit — graceful shutdown
  • nginx -s reload — reloading the configuration file
  • 启动就直接执行 nginx就可以了

 6. nginx的代理配置

location /api/1.0/shelter {
            proxy_pass http://127.0.0.1:8080/api/1.0/shelter;   //表示http://127.0.0.1/api1.0/shelter 的请求实际会被http://127.0.0.1:8080/api/1.0/shelter处理
}
原文地址:https://www.cnblogs.com/hzhuxin/p/8977025.html