Mobile wallpaper
639 字
3 分钟

nginx安装以及参数说明

安装nginx#

步骤命令
1.更新软件列表apt update
2.安装常用工具apt install -y curl tar wget gnupg2 lsb-release
3.安装nginxapt install nginx
⭐配置文件位置/etc/nginx/conf.d
4.启动nginxsystemctl start nginx
5.开机自启systemctl enable nginx
6.取消开机自启systemctl disable nginx

nginx管理命令#

步骤命令
启动nginxnginx -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.list

4.添加官方源到你的源列表:

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请求生成。
$schemeHTTP方法(如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安装以及参数说明/
作者
fang523
发布于
2025-12-01
许可协议
CC BY-NC-SA 4.0

目录