2

There's been a few questions like this but the most similar are unanswered and the rest have confounding factors. A deploy of previous-working-fine nginx is redirecting instead of proxying. The relevant section of the nginx.conf looks like this;

location /timesheets/ {
      gzip on;
      gzip_types    text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
      gzip_proxied   any;
      gzip_min_length 1000;
      gzip_comp_level 2;
      gzip_http_version 1.0;
      gzip_buffers 16 8k;

      gunzip on;
      gzip_static on;
      # Disable for IE < 6 because there are some known problems
      gzip_disable "MSIE [1-6].(?!.*SV1)";
      # Add a vary header for downstream proxies to avoid sending cached gzipped files to IE6
      gzip_vary on;

      proxy_set_header X-Forwarded-Host $host;
      proxy_set_header X-Forwarded-Server $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_pass http://timesheetserver.fqdn.com.au:8216$request_uri;
  proxy_intercept_errors on;
}

When accessing the server at the URL in the server_name part, they content at timesheetserver on port 8216 should be proxied to them. For some reason it's replying with 302 to the proxy_pass server, and because the users can't access port 8216 it's failing. What would cause this?

UPDATE: It 302's to the proxy_pass server if the index.html is left off the end. It works fine if the index.html is manually appended. I've added an index index.html; directive but it doesn't seem to handle the file being left off - how do I resolve?

1
  • 1
    Most likely this redirect is coming from your timesheetserver. May 17, 2017 at 11:12

1 Answer 1

1
  1. confirm to access http://timeserver:8216 from your nginx reverse proxy server with curl, wget etc.
  2. If you want to proxy_pass with name (not IP address), define resolver directive (DNS Server) with valid, ipv6 option in http, server, location block.
  3. Additionary define resolver_timeout directive.

location /timesheets/ {
      # http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver
      resolver 127.0.0.1 valid=30s ipv6=off;
      # http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver_timeout
      # give up and response error 
      resolver_timeout 5s;
      ### your existing configuration :-)
}

It is better that use FQDN(Fully Qualified Domain Name) for reverse proxy than timesheetserver.

Ref: http://nginx.org/en/docs/http/ngx_http_core_module.html#resolver

1
  • Thanks for answering Minish. It is an FQDN, I that got left out accidentally when I sanitised the file for public viewing. There's resolvers defined in the server stanza, and I've added a resolver_timeout directive. The behaviour remains the same, if the index.html is left off the URL nginx replies with a 302 to the content to be proxied, if it's added on, it works as intended.
    – Elomis
    May 30, 2017 at 3:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .