nginx常用配置

更新于 2025-11-08

手动配置fastcgi

location /
{
    try_files $uri $uri/index.html $uri.html @fcgi_passby;
}
location @fcgi_passby {
    fastcgi_pass   127.0.0.1:1082;
    fastcgi_pass_request_headers on; 
    include        fastcgi.conf;
}

querystring map

map '?$query_string' $qs {
  '?' '';
  default '?$query_string';
}

nginx获取自定义请求头

1、nginx是支持读取非HTTP标准的自定义header的,需要在http或者server下开启header的下划线支持:

underscores_in_headers on;

2、请求时添加X-Real-IP的header后,通过nginx获取header时使用$http_x_real_ip获取,一律采用小写,而且前面加了个http_前缀。

允许穿透到客户端的代理响应头

proxy_pass_header Server;

基本反代

#全部请求都反代到目标
location ~ ^/
{
  proxy_http_version 1.1;
  proxy_set_header X-Forwarded-For $remote_addr;
  proxy_set_header X-Real-Ip $remote_addr;
  proxy_set_header Front-End-Https on;
  proxy_set_header Host $http_host;
  proxy_pass_header Server;
  proxy_pass http://127.0.0.1:9445;
}
浙ICP备19039918号-1