Nopcommerce Issues working behind a proxy

1 year ago
Hi guys,

We are running a Nopcommerce store inside a company infrastructure that has two proxies. There will only one store.

- The first one has SSL certificate for the domain and redirects all traffic from HTTPS to the second proxy.
- The second proxy receives all HTTP traffic and redirects to our app server with IIS.

Problmens with url generation
First of all, we had problems with url generation.

Nopcommerce generates ip url instead of hostname urls. This could be by the redirection.
- The url were generated by .net core Url.RouteUrl helper methos.
- Store URL field is https://xxxxx.xxxx.xx/
- We have activated HTTP_X_FORWARDED_PROTO and second proxy is sending X-Forwarded-Proto, X-Forwarded-Server and X-Forwarded-Host correctly.

Like we have only one store, finally we solve introducing the next line of code to force host in all request.

            application.Use((context, next) =>
            {
                context.Request.Host = new Microsoft.AspNetCore.Http.HostString("xxxxx.xxx.xx");
                context.Request.Headers["Host"] = "xxxxx.xxx.xx";
                return next();
            });


Schedule task ends with error
- All task are running but we always get this error.
- We thing is related to proxy and security settings. ¿Is ther a way to

La tarea programada "Send emails" falló con el error "The SSL connection could not be established, see inner exception." (Tipo de tarea: "Nop.Services.Messages.QueuedMessagesSendTask, Nop.Services". Nombre de la tienda: "XXXXX XXX". Dirección de ejecución de la tarea: "https://xxxxx.xxxx.xx/scheduletask/runtask").
1 year ago
I´ve tested modifing middelware with the next code, but I can´t get correct host in request.

Nop.Web.Framewrok\Infrastructure\Extensions\ServiceCollectionExtensions.cs
In AddNopMvc method

            services.Configure<ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders = ForwardedHeaders.All;
                options.ForwardLimit = null;
                options.KnownNetworks.Clear();
                options.KnownProxies.Clear();

                options.KnownProxies.Add(IPAddress.Parse("xxx.xxx.xx.xx"));
                options.KnownProxies.Add(IPAddress.Parse("xx.xx.xx.xx"));
                options.KnownProxies.Add(IPAddress.Parse("127.0.0.1"));

                options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("xxx.xxx.xx.xx"), 24));
                options.KnownNetworks.Add(new IPNetwork(IPAddress.Parse("xx.xx.xx.xx"), 23));
            });


Then in Nop.Web.Framework.Infrastructure.NopMvcStartup.cs added next code in Configure method

application.UseForwardedHeaders();


Any ideas?
1 year ago
I'm using Nopcommerce on Linux behind an Apache proxy pass. Having same issue with image URLs in particular being contaminated with the internal local address (http://127.0.0.1:5000/etc) rather than the external client-facing URL.

I've found a solution by overriding the WebHelper class with custom implementations of GetStoreHost, GetStoreLocation, GetCurrentRequestProtocol, IsCurrentConnectionSecured, and GetCurrentIpAddress. It's fairly trivial and I was considering distributing it as a plugin but I do wonder if maybe I'm missing some very obvious built-in solution? It seems surprising to me if this isn't addressed out-of-the-box...
10 months ago
jima wrote:
I'm using Nopcommerce on Linux behind an Apache proxy pass. Having same issue with image URLs in particular being contaminated with the internal local address (http://127.0.0.1:5000/etc) rather than the external client-facing URL.

I've found a solution by overriding the WebHelper class with custom implementations of GetStoreHost, GetStoreLocation, GetCurrentRequestProtocol, IsCurrentConnectionSecured, and GetCurrentIpAddress. It's fairly trivial and I was considering distributing it as a plugin but I do wonder if maybe I'm missing some very obvious built-in solution? It seems surprising to me if this isn't addressed out-of-the-box...


Hi jima, we are facing exactly the same issue when we deployed the site from IIS to Linux.  On linux we set store SslEnabled = false and run the site without https.  The site is working but it was not loading images, by inspecting the image url, I can see it's using server ip instead of store url. i.e: 127.1.0.0.0/images/thumbs/xyz.png

Can you help me to resolve this?

Thank you!