Nginx 重写包含带空格的查询字符串的参数

Nginx 重写包含带空格的查询字符串的参数

我们在另一台主机上有一个 SAS 9.4 VisualAnalyticsViewer 页面,我想通过 443 公开展示。内部 SAS 服务器运行 Apache Tomcat 并仅监听 8343。如果可能的话,我宁愿不必更改 SAS 框上的每个 proxy_pass 语句,也不必自定义其端口,只需通过端口 443 提供单个页面。目前,我们的 Web 服务器使用 IFrames 链接到 8343 上的内部服务器,这些链接可以工作,但由于远程防火墙限制,限制了公共用户访问。我想将 Nginx 放在 Tomcat 服务器前面,让它监听 443。我的问题是处理重写语句中的空格。有人可以向我展示如何实现此目的的正确语法或正则表达式吗?

请注意;绕过 Nginx 并将带有空格的完整内部 URL 粘贴到本地浏览器中是有效的。

应用场景:

External Client Request:

https://apppub.domain.com/appVisualAnalyticsViewer Or,

https://apppub.domain.com/appVisualAnalyticsViewer/VisualAnalyticsViewer_guest.jsp?reportName=Report with Spaces&reportPath=/Some Data Path with Spaces/SubFolder/REPORT&appSwitcherDisabled=true

Nginx 代理检查 URI 查询字符串,然后将其重写或附加到端口 8343 上的内部 SAS 服务器。

Nginx Reverse Proxy:

https://appint.domain.com:8343/appVisualAnalyticsViewer/VisualAnalyticsViewer_guest.jsp?reportName=Report with Spaces&reportPath=/Some Data Path with Spaces/REPORT&appSwitcherDisabled=true

客户响应:

https://apppub.domain.com/appVisualAnalyticsViewer/(从远程客户端浏览器 URL 中剥离查询字符串)

以下是 apppub.conf(仅限此网站)、response.conf 和 proxy.conf 的完整配置,它们均由同一代理服务器上的多个站点使用。


Nginx Config:

    upstream appint { 
    least_conn; 
    server appint.domain.com:8343; 
}

server {

      listen 80;
      server_name apppub.domain.com;

      access_log off;
      autoindex off;

      location / {
         # Rate limit first 6 requests and burst next 4. Reject everything else
         limit_req zone=one burst=10 delay=6;
         return 301 https://$server_name$request_uri;
      }

}

server {

    listen 443 ssl;

     server_name apppub.domain.com;

   # Site Specific Logging Metrics
     access_log /var/log/nginx/apppub.access.log main_ext;
     error_log /var/log/nginx/apppub.error.log warn;

    autoindex off;

   # Load SSL cert and session security
      include /etc/nginx/conf.add/domain-ssl.conf;

   # Add Security and Caching Headers to responses
     add_header X-Frame-Options SAMEORIGIN;
     add_header X-Content-Type-Options nosniff;
     add_header X-XSS-Protection "1; mode=block";
     add_header Cache-Control no-cache;
     add_header Vary Accept-Encoding;
     expires 5m;

   # Load client buffers and timeout response
      include /etc/nginx/conf.add/response.conf; (See Below)

   # Load Gzip mime type compression
      include /etc/nginx/conf.add/gzip.conf;


    # /appVisualAnalyticsViewer/

    location ~ ^/appVisualAnalyticsViewer {

       if ($args !~* "Report Name with Spaces"){
           set $report "VisualAnalyticsViewer_guest.jsp?reportName=Report with Spaces&reportPath=/Some Data Path with Spaces/REPORT&appSwitcherDisabled=true";
           rewrite ^(.*)$ $report break; 
           **(What's the correct syntax for a rewrite?)**
       }

       include /etc/nginx/conf.add/proxy.conf; (See Below)
       proxy_pass https://appint;

     }
Response Config:
Form POST submissions

client_body_buffer_size 1024K;
Form POST maxiumum size

client_max_body_size 16m;
Max client header size

client_header_buffer_size 2k;
Max time to receive client headers/body from buffer

client_body_timeout 5s; client_header_timeout 5s;
Max time to keep a connection open to clients

keepalive_timeout 5s;
Max time for the client accept/receive a response

send_timeout 5s;
Skip buffering for static files

sendfile on;
Optimize sendfile packets

tcp_nopush on; }
    Proxy Config:

    Proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header
    X-Forwarded-Host $host; proxy_set_header X-Forwarded-Port $server_port;

    proxy_set_header Connection ""; # Enable keepalives proxy_set_header
    Accept-
    Encoding ""; # Optimize encoding proxy_set_header X-Forwarded-Host
   $host:$server_port; proxy_set_header X-Forwarded-Server $host;
   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

   proxy_buffers 32 4m; proxy_busy_buffers_size 25m; proxy_buffer_size 512k;
   proxy_headers_hash_max_size 512; proxy_headers_hash_bucket_size 128;
   proxy_ignore_headers "Cache-Control" "Expires"; proxy_max_temp_file_size 0; proxy_next_upstream error timeout invalid_header http_500;
   proxy_connect_timeout 90; proxy_read_timeout 90; proxy_send_timeout 90; 
   proxy_intercept_errors off;

答案1

你们可能对此感兴趣。我找出了语法错误,并最终使用位置周围的单引号纠正了它。

'一些带有空格的字符串'

相关内容