Nginx设置之自定义请求头

时间:2025-05-12 09:49:29
  • user nginx;
  • worker_processes 1;
  • #error_log /var/log/nginx/error.log warn;
  • #pid /var/run/;
  • events {
  • worker_connections 1024;
  • }
  • http {
  • include ;
  • default_type application/octet-stream;
  • log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  • '$status $body_bytes_sent "$http_referer" '
  • '"$http_user_agent" "$http_x_forwarded_for"';
  • #access_log /var/log/nginx/access.log main;
  • sendfile on;
  • tcp_nopush on;
  • keepalive_timeout 65;
  • gzip on;
  • underscores_in_headers on; # 用于解决请求头中包含下划线'_'key
  • server {
  • listen 8888;
  • listen [::]:8888;
  • server_name _;
  • root dist/;
  • location / {
  • try_files $uri /index.html;
  • }
  • # 配置接口代理
  • location ^~ /fileCenter {
  • proxy_set_header keyid 81dcfe44-0e3f-4161-a6e6-******c30fb8; # 自定义请求头keyid
  • proxy_pass https://****.com:8060;
  • rewrite "^/fileCenter/(.*)$" /$1 break;
  • }
  • # 配置接口代理
  • # location ^~ /baidu {
  • # proxy_pass https://;
  • # rewrite "^/baidu/(.*)$" /$1 break;
  • # }
  • error_page 500 502 503 504 /50;
  • location = /50 {
  • root /app;
  • }
  • location ~ /\.map {
  • deny all;
  • }
  • }
  • }