nopCommerce and reverse proxy

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
9 years ago
Hi,

we are trying to use a reverse proxy wtih nopCommerce. Is there any best practice guideline or documentation available on how to configure nopCommerce for this scenario?

In our case all traffic should be HTTPS only. So our reverse proxy redirects all HTTP-Requests to HTTPS. In our network the reverse proxy and the IIS with nopCommerce communicate only via HTTP. The reason for this is, that we use the reverse proxy for multiple applications, so we only need a single server where we can store all our SSL-Certificates and network configurations. The result is, that nopCommerce only handles HTTP-Requests. The problem is however, that all resource links like images, javascript and css files should be referenced via HTTPS. If they are referenced via HTTP the user will get a certificate warning, because secure and unsecure content is mixed.
We can not simply use the "enable SSL" setting in nopCommerce, because this creates a redirect loop ( nopCommerce redirects to HTTPS, reverse proxy sends HTTP request, nopCommerce redirects to HTTPS, ... )

Any help would be appreciated.
9 years ago
Hi,

Try the following:

1. Open Nop.Core\WebHelper.cs file
2. Find IsCurrentConnectionSecured() method
3. Uncomment the follwoing line of code:
useSSL = _httpContext.Request.ServerVariables["HTTP_CLUSTER_HTTPS"] == "on" ? true : false;


Please let me know if it helps
9 years ago
Hi,

thank you for you response. I will try your suggestion, however it will probably a couple of days until I will be able to. I will report back with with the results as soon as I am able to.
3 years ago
Hello,
I install nopcommerce on Ubuntu server using nginx reverse proxy to make it accessible on web.
The problem is StoreLocation does not return correct URL , and some times return IP address and some times return another domain point to this server as Store URL. and becuase site run on https and IP and other domain dont have SSL certificate, our logo , slider and product images some times do not display correctly.
When I reset nginx server and make a request by correct URL , it will show for a while with correct storelocation.
How can I fix it to use domains are in store settings?
3 years ago
Hi Ashian,

Have you tried changing this setting to true in appsettings.json?

  //Also set to "true" the next settings if you use a reverse proxy server (for example, if you host your site on Linux with Nginx/Apache and SSL)
    "UseHttpXForwardedProto": false,

Jon
3 years ago
Hi
Yes I did this change,  and without that setting I have some troubles to open site in https mode.
2 years ago
Hi guys

First of all, I am trying to configure the system to have a reverse proxy with nginx, After that I have to configure the ssl certificate with letsencrypt.

The problem is that I can't get nginx to do a proper redirect to Kestrel and the result I get is a error code 502 .

I attach my configuration files in case anyone has an idea of what could be going on

Thank you very much friends for the time

docker-compose
================
version: "3.8"
services:

  nginx_demo:
    container_name: nginx_demo
    image: nginx:1.20.2-alpine
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
    ports:
      - 80:80
    restart: always
    networks:
      - nop450_demo
    depends_on:
      - nop450_web_demo

  nop450_web_demo:
    image: nopcommerceteam/nopcommerce:4.50.1
    container_name: nop450_web_demo
    # ports:
    #   - "80:80"
    # - "5000:5000"
    networks:
      - nop450_demo
    expose:
      - 5000
    volumes:
      - $PWD/web/Themes:/app/Themes
      - $PWD/web/Plugins:/app/Plugins
      - $PWD/web/App_Data:/app/App_Data
    depends_on:
      - nop450_db_demo

  nop450_db_demo:
    image: mysql:5.7
    container_name: nop450_db_demo
    command: mysqld --default-authentication-plugin=mysql_native_password
    restart: always
    volumes:
      - $PWD/mysql:/var/lib/mysql
    networks:
      - nop450_demo
    environment:
      MYSQL_ROOT_PASSWORD: xxxxxxxxxxx
      MYSQL_DATABASE: xxxxxxxxxx
      MYSQL_USER: xxxxxxxxxxxx
      MYSQL_PASSWORD: zxxxxxxxxxx


networks:
  nop450_demo: null



nginx config
================

events {}

http {

    upstream web_nop450_web_demo{
        server nop450_web_demo:5000;
    }

  server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name viajesroxana.com;
    location / {
        proxy_pass         http://web_nop450_web_demo;
        proxy_http_version 1.1;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection keep-alive;
        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;
    }    
  }
}


appseting.json
==========

{
  "ConnectionStrings": {
    "ConnectionString": "server=xxxxxxxx;database=xxxxxxxx;allowuservariables=True;user id=xxxxxxxxxxxxxx;password=xxxxxxxxxxx",
    "DataProvider": "mysql",
    "SQLCommandTimeout": null
  },
  "AzureBlobConfig": {
    "ConnectionString": "",
    "ContainerName": "",
    "EndPoint": "",
    "AppendContainerName": true,
    "StoreDataProtectionKeys": false,
    "DataProtectionKeysContainerName": "",
    "DataProtectionKeysVaultId": ""
  },
  "CacheConfig": {
    "DefaultCacheTime": 60,
    "ShortTermCacheTime": 3,
    "BundledFilesCacheTime": 120
  },
  "CommonConfig": {
    "DisplayFullErrorStack": false,
    "UserAgentStringsPath": "~/App_Data/browscap.xml",
    "CrawlerOnlyUserAgentStringsPath": "~/App_Data/browscap.crawlersonly.xml",
    "UseSessionStateTempDataProvider": false,
    "MiniProfilerEnabled": false,
    "ScheduleTaskRunTimeout": null,
    "StaticFilesCacheControl": "public,max-age=31536000",
    "SupportPreviousNopcommerceVersions": true,
    "PluginStaticFileExtensionsBlacklist": "",
    "ServeUnknownFileTypes": false
  },
  "DistributedCacheConfig": {
    "DistributedCacheType": "redis",
    "Enabled": false,
    "ConnectionString": "127.0.0.1:6379,ssl=False",
    "SchemaName": "dbo",
    "TableName": "DistributedCache"
  },
  "HostingConfig": {
    "UseProxy": false,
    "ForwardedProtoHeaderName": "",
    "ForwardedForHeaderName": "",
    "KnownProxies": ""
  },
  "InstallationConfig": {
    "DisableSampleData": false,
    "DisabledPlugins": "",
    "InstallRegionalResources": true
  },
  "PluginConfig": {
    "ClearPluginShadowDirectoryOnStartup": true,
    "CopyLockedPluginAssembilesToSubdirectoriesOnStartup": true,
    "UseUnsafeLoadAssembly": true,
    "UsePluginsShadowCopy": true
  },
  "WebOptimizer": {
    "EnableJavaScriptBundling": true,
    "EnableCssBundling": true,
    "JavaScriptBundleSuffix": ".scripts",
    "CssBundleSuffix": ".styles",
    "EnableCaching": true,
    "EnableMemoryCache": true,
    "EnableDiskCache": true,
    "EnableTagHelperBundling": false,
    "CdnUrl": null,
    "CacheDirectory": "/app/wwwroot/bundles",
    "AllowEmptyBundle": true,
    "HttpsCompression": 2
  }
}
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.