1

I need to configure nginx, which is acting as reverse proxy for my site (myportal.com). nginx can connect to the actual site via squid proxy.

client -> nginx -> Squid Proxy -> web server.

Note:

a. Client assumes nginx as the web server (of myportal.com).

b. nginx fetches the content from actual server (myportal.com), via squid proxy.

Thanks Tarun. We have successfully configured nginx as reverse proxy when the destination web server is reachable directly. But while connect to the web serve behind squid. We are facing issue. As the Client has to connect to the nginx assuming it is the destination server (hence no proxy headers sent). –

We tried the following too.

upstream @squid {
    server localhost:3128;
}

server {
    listen 80;
    server_name relay.example.com;

    location / {
        proxy_pass http://@squid/$scheme://$host$uri;

        proxy_set_header Host $host;
        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 Request-URI $request_uri;

        proxy_redirect off;
    }
}
4
  • Show us what config you have tried and what issues you are facing Aug 27, 2017 at 5:51
  • Edit question and updated code, don't paste it here in command Aug 27, 2017 at 20:38
  • @TarunLalwani.. any suggestions? Sep 11, 2017 at 4:28
  • can you try setting the proxy to be transparent? http_port 3128 transparent. You don't want proxy protocol to happen Sep 11, 2017 at 5:59

1 Answer 1

0

Give a try to this configuration, it is using Nginx as a reverse proxy and caching, probably could help you get an idea:

    ...
    proxy_buffering    on;
    proxy_cache_path   /home/cache levels=1:2 keys_zone=myportal:256m max_size=5g inactive=24h use_temp_path=off;
    proxy_buffer_size  8k;
    proxy_buffers      8 24k;

    server {
        listen       80;
        server_name  _;

        location / {
            proxy_cache myportal;
            proxy_cache_use_stale updating error timeout invalid_header http_500 http_502 http_503 http_504;
            proxy_cache_revalidate on;
            proxy_cache_min_uses 1;
            proxy_cache_lock on;
            proxy_cache_valid 200 301 304 2d;
            proxy_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie;

            proxy_redirect off;
            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 Host myportal.tld;
            proxy_set_header Connection "";
            proxy_http_version 1.1;
            proxy_pass https://myportal.tld/;
        }
    }
    ...
2
  • 1
    Thanks @nbari . The reverse proxy configuration is working fine, when the destination web server is reachable directly (from nginx) but if it is behind the squid. We are facing issue Aug 27, 2017 at 21:23
  • my guess is that you need to check proxy_set_header Host myportal.tld; what problem you /error you get ?
    – nbari
    Aug 27, 2017 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.