Apache-2.2

無法通過 nginx 代理訪問 apache Web 伺服器

  • January 25, 2015

我有 apache 伺服器在以下 23.xxx.xxx.10:80 上執行。我正在嘗試使用如下定義的 nginx 代理訪問其中一個文件夾(/var/www/cfbrokerlogs)。但是,當我嘗試從瀏覽器訪問時,我得到了 net::ERR_TOO_MANY_REDIRECTS 。我不確定我需要打開什麼才能使其工作?

nginx.conf

location /cfbrokerlogs/ {
 proxy_pass                 http://23.xxx.xxx.10:80/cfbrokerlogs;
 proxy_set_header           X-Real-IP   $remote_addr;
 proxy_set_header           X-Forwarded-For  $proxy_add_x_forwarded_for;
 proxy_set_header           X-Forwarded-Proto  $scheme;
 proxy_set_header           X-Forwarded-Server  $host;
 proxy_set_header           X-Forwarded-Host  $host;
 proxy_set_header           Host  $host;

 client_max_body_size       10m;
 client_body_buffer_size    128k;

 proxy_connect_timeout      90;
 proxy_send_timeout         90;
 proxy_read_timeout         90;

 proxy_buffer_size          4k;
 proxy_buffers              4 32k;
 proxy_busy_buffers_size    64k;
 proxy_temp_file_write_size 64k;
}

Apache 配置 (apache2.conf)

   <VirtualHost *:80>


   WSGIDaemonProcess _graphite processes=5 threads=5 display-name='%{GROUP}' inactivity-timeout=120 user=_graphite group=_graphite
   WSGIProcessGroup _graphite
   WSGIImportScript /usr/share/graphite-web/graphite.wsgi process-group=_graphite application-group=%{GLOBAL}
   WSGIScriptAlias / /usr/share/graphite-web/graphite.wsgi

  Alias /content/ /usr/share/graphite-web/static/
     <Location "/cfbrokerlogs/">
     SetHandler None  
     Header set Access-Control-Allow-Origin "*"
     Header set Access-Control-Allow-Methods "GET, OPTIONS"
     Header set Access-Control-Allow-Headers "origin, authorization, accept"
      </Location>

     Header set Access-Control-Allow-Origin "*"
     Header set Access-Control-Allow-Methods "GET, OPTIONS"
     Header set Access-Control-Allow-Headers "origin, authorization, accept"


            Alias /cfbrokerlogs  /var/www/cfbrokerlogs
           <Directory /var/www/cfbrokerlogs>
               Options Indexes FollowSymLinks MultiViews
               AllowOverride All
               Order allow,deny
               allow from all
           </Directory>

   </VirtualHost>

來自nginx 的文件

如果 proxy_pass 指令使用 URI 指定,則當請求傳遞到伺服器時,與位置匹配的規範化請求 URI 的部分將替換為指令中指定的 URI。

所以這裡這意味著如果你點擊http://<domain>/cfbrokerlogs/foo那麼它將按照http://23.xxx.xxx.10:80/cfbrokerlogsfoo指令proxy_pass轉發。

proxy_pass指令 URI 添加尾部斜杠或將其從位置中刪除。

引用自:https://serverfault.com/questions/662267