Prestashop behind NGINX reverse proxy

I want to run Presta behind an Nginx reverse proxy. Presta 8.2.1 is running on Nginx 1.26.3. I’ve prepared:

  • Reverse proxy config: https://pastebin.com/Xcx2s93f
  • Presta (backend) config: https://pastebin.com/q1V8y4zx
  • In Presta’s database, in the ps_shop_url table, I set the domain and domain_ssl columns to test-proxy.example.com and test-proxy.example.com respectively. By default, / in physical_uri.
  • Backoffice works perfectly. In it, under Shop Parameters → Traffic & SEO, I have:

Set up URLs:

  • Friendly URL → Yes
  • Redirect to the canonical URL → 302 Moved Temporarily

Set shop URL:

  • Shop domain → test-proxy.example.com
  • SSL domain → test-proxy.example.com
  • Base URI → /

The problem I deal with:
When I go to test-proxy.example.com, I get a redirect loop from test-proxy.example.com to test-proxy.example.com with a 302 status code. If I change the “Redirect to the canonical URL” option in the backoffice to 301, then I get a redirect loop with a 301 status code.

Visiting any non-existent URL, e.g. test-proxy.example.com/test, generates the correct response /index.php?controller=404.

Visiting any existing URL, e.g. test-example.com/about-us, causes a redirect loop: /about-us/ 301 → /about-us 302 → /about-us 302 → /about-us and so on in a loop.

If I only change in the database, in the above-mentioned table, test-proxy.example.com in both columns to presta-us.example.com, then the front works, but there’s a problem with the cart. This is understandable behavior.

Of course, when I completely delete reverse proxy, presta-us.example.com works smoothly like it should. :slight_smile:

I have no idea what’s going on anymore. I checked the values of the headers passed by the proxy. I also prepared a script that displayed the header values: I am not able to put more than two links in the new post as a new user.

The goal:
Working Prestashop front behind nginx reverse proxy.
I also set up Wordpress behind reverse proxy, which works - frontend/backoffice - like a charm.

Hey @Piotr_Bracha! I am looking at your config and it is quite simple so I am not entirely sure the issue is with NGINX itself? In both configs you have a return directive to redirect HTTP to HTTPS where you explicitly define a 301 status code. On the other hand, when using proxy_pass, the status code is whatever the backend replies, so ideally it would be a 200 code.

Per your description, this seems an issue with the “Redirect to the canonical URL → 302 Moved Temporarily” setting sending your requests back to test-proxy.example.com given you are setting them up as your “canonical” domains. So basically right now your environment is in a loop where NGINX redirects you to Prestashop and Prestashop redirects you to the canonical domain which is the NGINX test proxy domain.

You mention that changing the domain in the database makes the frontend work. That is likely the solution here. I am not entirely sure what the issue with the cart might be, but that’s probably what you need to look into.

P.S.: You can always add your config/scripts/snippets as a code block in the post vs using a link :slightly_smiling_face:

Thank you @alessandro . To be honest, I’m at a point where I don’t know what the problem is anymore. :slight_smile:

I set the post there, because “maybe” there is something wrong with my nginx reverse proxy configuration. Who knows? :slight_smile:

After changing url in the database frontend works but the cart doesn’t. After entering /cart url the [sub]domain is changed from test-proxy to presta-us and the cart becomes empty. Prestashop need to have domain and domain_ssl set up as test-proxy.example.com to preserve sessions, cookies, generate links and so on. :slight_smile:

Btw I made an update of my reverse proxy config

    location / {
        proxy_pass https://presta-us.example.com;
        proxy_ssl_server_name on;
        proxy_ssl_name presta-us.example.com;

        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Port $server_port;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Connection "";

        access_log /var/log/nginx/domains/test-proxy.example.com.log combined;
        error_log  /var/log/nginx/domains/test-proxy.example.com.error.log info;
    }

The same for /admin9254z9q7u. I have 502 Bad Gateway for both. The log (test-proxy and presta-us are on the same server - testing environment):

2025/08/11 14:37:38 [error] 3128567#3128567: *68912 peer closed connection in SSL handshake while SSL handshaking to upstream, client: 167.71.55.16, server: test-proxy.example.com, request: "GET / HTTP/1.1", upstream: "https://167.71.55.16:443/", host: "test-proxy.example.com"

PS
I tried use the code snippet for configs but then first server block wasn’t included into snippet, so I decided to use pastebin. :slight_smile:

Sadly the only thing I can really deduce from your config is that as long as you use the redirect setting in Prestashop to redirect to test-proxy.example.com, you are going to be running into this endless redirect loop issue. I am not familiar at all with Prestashop though, so I would probably suggest asking in their community to see if they have any suggestions.

Edit: Just saw your latest edit – I would revert back to your prior config if it was working. The error log you shared means that something is wonky with your SSL certs. You first need to figure out how to disable or fix the Redirect to the canonical URL → 302 Moved Temporarily setting within Prestashop, and that is something I really cannot help you with :sweat_smile:

I tried with clean presta 8.2.1 and also 1.7.8.10. My config works perfectly front/backoffice, so the problem is probably with some module which gives “SEO & URLs” option in the backoffice –> Preferences. :slight_smile:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.