smartstore / Smartstore

A modular, scalable and ultra-fast open-source all-in-one eCommerce platform built on ASP.NET Core 7
http://www.smartstore.com/
GNU Affero General Public License v3.0
1.2k stars 447 forks source link

How to run Smartstore in a subfolder? #998

Closed Algorithman closed 9 months ago

Algorithman commented 9 months ago

Is your feature request related to a problem? Please describe. I try to run Smartstore in /shop/ on our domain. I changed the Store Url to https://our.domain/shop/ but nothing changed. If i try to access /shop/ i get a 404. Also all media urls aren't using the base path (even with the AlwaysGenerateAbsoluteUrls setting on). For the media Urls i consider this a bug since the source code doesn't use the store baseUrl at all.

 var httpContext = httpContextAccessor.HttpContext;
 string pathBase = "/";

 if (httpContext != null)
 {
     var request = httpContext.Request;
     pathBase = request.PathBase;

     var cdn = storeContext.CurrentStore.ContentDeliveryNetwork;
     if (cdn.HasValue() && !CommonHelper.IsDevEnvironment && !httpContext.Connection.IsLocal())
     {
         _host = cdn;
     }
     else if (mediaSettings.AutoGenerateAbsoluteUrls)
     {
         _host = "//{0}{1}".FormatInvariant(request.Host, pathBase);
     }
     else
     {
         _host = pathBase;
     }
 }

Is there a tutorial somewhere how to use it in a subfolder?

Thx

zihniartar commented 9 months ago

For example, we use our demo stores in virtual folders: https://core.smartstore.com/backend

Do you use linux or windows? How did you set up the site? Under Windows in IIS, an application must be created in the site for the virtual folder /shop. If you use Linux, I (or you) would have to google it.

Algorithman commented 9 months ago

Linux, at the moment as reverse proxy via nginx. And I can run it, but the returned urls (specially the links to javascript/css/images) are without /shop/, disregarding the store's baseUrl setting completely.

zihniartar commented 9 months ago

It says above that you get a 404 when you call /shop/. Is the store accessible or not?

Have you changed the store URL in the Smartstore configuration under Configuration -> Shops?

Can you please insert the NGINX configuration of the site or folder here.

Algorithman commented 9 months ago

I changed it in Configuration->Shops. Even restarted nginx and Smartstore. On linux, all the urls are returned with basepath /, regardless of the setting in Store.Url.

Nginx config:

        location ~ ^/shop/ {
                        client_max_body_size 10M;

                        proxy_pass         http://127.0.0.1:5000;
                        proxy_http_version 1.1;
                        proxy_set_header   Upgrade $http_upgrade;
                        proxy_set_header   Connection keep-alive;
                        proxy_set_header   Host $host;
                        proxy_cache_bypass $http_upgrade;
                        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                        proxy_set_header   X-Forwarded-Proto $scheme;
                        proxy_read_timeout 240s;
                        proxy_send_timeout 240s;
                        add_header X-Frame-Options "SAMEORIGIN";
                   }

Also different from an IIS environment: The cookies are set with / as path instead of /shop/ (like /frontend/ or /backend/ in the demo shop).

after some time and more probing I fixed it for my case with setting the AppBasePath (builder.ApplicationBuilder.UsePathBase("/shop"); in BuildPipeline in my Startup.cs) in my module to /shop, which solves it, but only fixes the symptom. The problem (at least on linux) seems to be that the store url isn't processed properly in a reverse proxy environment on linux.

muratcakir commented 9 months ago

Have you tried setting your base path in proxy_pass, e.g. proxy_pass http://localhost:5000/shop/; ? PathBase is always a server config issue and has nothing to do with the app. But: the configured shop URL in the Smartstore backend must reflect this setting.

Algorithman commented 9 months ago

If I set proxy_pass to http://localhost:5000/shop/ and disable the UseBasePath call then the application is unreachable. The Shop-Url is set to https://my.domain/shop/. Like I said (maybe it is a aspnetcore issue), on linux it seems that the webserver doesn't set the baseurl. And I'm not that into asp that I could say where it should get the value from in a reverse proxy environment.

Algorithman commented 9 months ago

Good morning. Didn't look enough yesterday, seems nginx doesn't want a path in the proxy_pass (nginx: [emerg] "proxy_pass" cannot have URI part in location given by regular expression, or inside named location, or inside "if" statement, or inside "limit_except" block in /etc/nginx/sites-enabled/default) So http://127.0.0.1/shop/ is out of the question.

Algorithman commented 9 months ago

Another thing I noticed: You can start Smartstore with argument --urls http://localhost:5020 for example to run it on port 5020. Which works fine but only if you have already installed the database. The installer itself doesn't seem to recognize the port change (and maybe also not the host).

Algorithman commented 9 months ago

Don't bother looking for it. ASPNetCore doesn't support it yet (at least not the released versions). But for the future: There is already code for processing X-Forwarded-Prefix headers. See here I go with my temporary solution then until the update is in the nugets and Smartstore is updated :)