Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache with and without subdomain are causing inconsistent urls. #6160

Open
peterberkenbosch opened this issue Mar 12, 2015 · 8 comments
Open

Comments

@peterberkenbosch
Copy link
Member

Steps to reproduce:

1- In the Spree store deployed soemwhere (let's say, example.com), set up 2 subdomains, e.g.: www and production.

2- Visit the page of a product that has 2 variants using production.example.com.

3- Visit one variant of the product using production.example.com, and the other variant using www.example.com

4- Navigate through variants.. notice how the url of a variant is www.example.com/* and the other is production.example.com/*, and it changes when visiting these variants.

5- Search for the same product from www.example.com and note how the subdomain of the variants do not remain consistent.

So, the issue is caused by cache: when the page is cached, then it's with one subdomain, and when visited from another then it looks inconsistent.

@JDutil
Copy link
Member

JDutil commented Mar 12, 2015

Hmm I would argue you should only be serving your store over a canonical url... Solution should be easy enough though just add the request subdomain/domain to the cache key.

@NathanNg
Copy link

I also got inconsistent url on my app especially on product page. I deployed a vanilla spree app 3.0 on heroku and got http://0.0.0.0/products/ruby-on-rails-ringer-t-shirt. I fixed this by going into "admin > clear cached" but the problem comes back the next day.

You can test from the below app and click on the first product. In addition, you can use spree@example.com to sign into the admin to clear cached.

https://boong.herokuapp.com/

@boxtels
Copy link

boxtels commented May 19, 2015

this something we have been dealing with ourselves, to fix this:
we modified the nginx configs to only use https://mydomain.com/*, and reset the cache.

the problem is that the page is saved to cache after a user requests it, so if a user requests http://0.0.0.0/particular-path that path is found locally and therefore cached.

@NathanNg
Copy link

boxtels,

Where do you modify the nginx config? in the Profile? and what is script do you put it there so it use https://mydomain.com.

@boxtels
Copy link

boxtels commented Jul 11, 2015

@NathanNg
This is not a spree bug fix, just a workaround.
look up and carefully test multiple nginx configurations / rewrite rules
here's what i used. It's working for us.

  1. we wanted to only use domain.com so we used rewrite for all www.mydomain.com requests to mydomain.com
  2. our server name was getting picked up as well production.mydomain.com same as www.mydomain.com rewrite.
  3. last one was for the public or local ip address, 0.0.0.0 would be your public ip address.
        if ($host ~* www\.(.*)) {
          set $host_without_www $1;
          rewrite ^(.*)$ $scheme://$host_without_www$1 permanent;
        }

        if ($host ~* production\.(.*)) {
          set $host_without_www $1;
          rewrite ^(.*)$ $scheme://$host_without_www$1 permanent;
        }

        if ($host ~* 0.0.0.0) {
          rewrite ^ $scheme://mydomain.com$request_uri permanent;
        }

@nishant-cyro
Copy link
Contributor

@priyank-gupta @damianlegawiec @Mafi88 - I am able to verify the issue, one solution for this seems to me is we should use _path route helpers instead of _url helpers (at least in views have caching).

Please let me know your thoughts on this.

@Mafi88
Copy link
Contributor

Mafi88 commented Feb 4, 2016

@nishant-cyro @priyank-gupta @damianlegawiec Or, as @JDutil suggested, we could probably "add the request subdomain/domain to the cache key". No idea which one is a better approach.

@priyank-gupta
Copy link
Contributor

@Mafi88 @nishant-cyro I think adding subdomain/domain to the cache key may be a better approach. As user should not be restricted to work on respective preferred style of coding. Also, there may be cases when _url helpers are required.
Preferably, I will go with @JDutil about canonical url usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants