639 字
3 分钟
nginx安装以及参数说明
安装nginx
| 步骤 | 命令 |
|---|---|
| 1.更新软件列表 | apt update |
| 2.安装常用工具 | apt install -y curl tar wget gnupg2 lsb-release |
| 3.安装nginx | apt install nginx |
| ⭐配置文件位置 | /etc/nginx/conf.d |
| 4.启动nginx | systemctl start nginx |
| 5.开机自启 | systemctl enable nginx |
| 6.取消开机自启 | systemctl disable nginx |
nginx管理命令
| 步骤 | 命令 |
|---|---|
| 启动nginx | nginx -c /etc/nginx/nginx.conf |
| 停止 | nginx -s quit |
| 强制停止 | nginx -s stop |
| 重新加载 | nginx -s reload |
无法安装的解决办法
若无法通过apt安装,可是软件源设置问题
1.下载nginx PGP签名文件:wget http://nginx.org/keys/nginx_signing.key
2.安装nginx PGP签名文件:apt-key add nginx_signing.key
3.添加官方源到你的源列表:
echo "deb http://nginx.org/packages/debian/ $(lsb_release -cs) nginx" | tee /etc/apt/sources.list.d/nginx.list4.添加官方源到你的源列表:
echo "deb-src http://nginx.org/packages/debian/ $(lsb_release -cs) nginx" | tee -a /etc/apt/sources.list.d/nginx.list然后再次更新软件列表,运行安装命令即可。
在非标准linux系统中启动nginx
例如openwrt,无法使用systemctl管理系统中的服务。
先通过opkg软件包管理程序安装nginx。
| 步骤 | 命令 |
|---|---|
| 授权开机自启 | chmod 755 /etc/init.d/nginx |
| 启动服务 | service nginx start |
| 停止服务 | service nginx stop |
| 开机自启服务 | service nginx enable |
| 取消开机自启 | service nginx disable |
匹配规则和优先级
| 代码 | 解释 |
|---|---|
| location = | #精准匹配 |
| location ^~ | #带参前缀匹配 |
| location ~ | #正则匹配(区分大小写) |
| location ~* | #正则匹配(不区分大小写) |
| location /a | #普通前缀匹配,优先级低于带参数前缀匹配。 |
| location / | #任何没有匹配成功的,都会匹配这里处理 |
参数说明
| 参数 | 解释 |
|---|---|
| $args | 这个变量等于请求行中的参数,同$query_string |
| $content_length | 请求头中的Content-length字段。 |
| $content_type | 请求头中的Content-Type字段。 |
| $document_root | 当前请求在root指令中指定的值。 |
| $host | 请求主机头字段,否则为服务器名称。 |
| $http_user_agent | 客户端agent信息 |
| $http_cookie | 客户端cookie信息 |
| $limit_rate | 这个变量可以限制连接速率。 |
| $request_method | 客户端请求的动作,通常为GET或POST。 |
| $remote_addr | 客户端的IP地址。 |
| $remote_port | 客户端的端口。 |
| $remote_user | 已经经过AuthBasicModule验证的用户名。 |
| $request_filename | 当前请求的文件路径,由root或alias指令与URI请求生成。 |
| $scheme | HTTP方法(如http,https)。 |
| $server_protocol | 请求使用的协议,通常是HTTP/1.0或HTTP/1.1。 |
| $server_addr | 服务器地址,在完成一次系统调用后可以确定这个值。 |
| $server_name | 服务器名称。 |
| $server_port | 请求到达服务器的端口号。 |
| $request_uri | 包含请求参数的原始URI,不包含主机名,如:”/foo/bar.php?arg=baz”。 |
| $uri | 不带请求参数的当前URI,$uri不包含主机名,如”/foo/bar.html”。 |
| $document_uri | 与$uri相同。 |
nginx安装以及参数说明
https://www.pidexe.com/posts/nginx安装以及参数说明/