# Nginx

## 配置文件

默认配置文件`nginx.config`

默认配置文件目录`/usr/local/nginx/conf`，`/etc/nginx`或`/usr/local/etc/nginx`

## 命令行

`nginx -s stop`停止nginx进程

`nginx -s quit`等待当前请求完成后停止nginx进程

`nginx -s reload`重新加载配置文件

`nginx -s reopen`重新开始日志文件

`kill -s QUIT 1628`发送QUIT信号给指定进程ID的进程

`ps -ax | grep nginx`列出所有运行中的nginx进程

## 配置文件结构

`http`与`event`指令位于主上下文中，`server`位于`http`中，`location`位于`server`中

```
http {
    server {
    }
}
```

### web server

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

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

匹配文件扩展名

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

### proxy server

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

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

### `location`匹配规则

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

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

首先按序匹配正则表达式，如果满足，则不再继续匹配。如果没有满足的正则表达式，则匹配前缀最长的`location`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://keenv.gitbook.io/notes/nginx.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
