在 Debian 系统中,Nginx 配置文件通常位于 /etc/nginx/nginx.conf
。在这个配置文件中,你可以使用变量来简化配置和提高灵活性。以下是一些常用的 Nginx 变量:
$scheme
:当前请求的协议(http 或 https)。$host
:当前请求的主机名(包括端口号,如果有的话)。$server_name
:当前请求的服务器名称。$request_uri
:当前请求的 URI,不包括协议、主机名和端口。$document_root
:当前请求的文档根目录。$fastcgi_script_name
:FastCGI 脚本的路径。$fastcgi_param
:传递给 FastCGI 脚本的参数。$http_user_agent
:客户端 User-Agent 头部。$http_cookie
:客户端 Cookie 头部。$remote_addr
:客户端的 IP 地址。$remote_port
:客户端的端口号。$server_port
:服务器的端口号。以下是一个简单的 Nginx 配置文件示例,演示了如何使用这些变量:
http {
server {
listen 80;
server_name example.com www.example.com;
root /var/www/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
}
在这个示例中,我们使用了 $host
变量来设置 server_name
,使用 $document_root
变量来设置文档根目录,以及使用 $fastcgi_script_name
和 $fastcgi_param
变量来配置 FastCGI 脚本参数。
你可以根据需要使用这些变量来定制你的 Nginx 配置。更多关于 Nginx 变量的信息,你可以查阅官方文档:http://nginx.org/en/docs/variables.html