Images use IP address some times

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
5 years ago
sina.islam wrote:
Yeah I thought that was a little weird too. I dont see any console errors in Chrome Debug. Wonder if they just removed it?

I think you should go with this setting. Because the GetStoreHost method have some changes at nopcommerce4.1. The setup is ok, go for it.


Thanks Bud. I'll give it a try and report back
3 years ago
I have exactly the same problem. The logo image intermittently disappears as website references it trough ip address, not through domain name.  By any chance, have you found a solution to this problem?
3 years ago
I'm still having this problem.  Any info?  It's not a good look
3 years ago
@arcandoak can you please explain this in detail so we can provide you solution on this.
3 years ago
I believe this is caused by the image cache.

The first hit on your website via the ip address http://<your-ip>, after the cache is cleared, causes the images to be cached with the IP address in the URL, rather than the domain name.
Images then fail to load, as the SSL Certificate is for the https://your.domain.com/

You can test this by clearing the cache, and going to https://<your-ip>/

The fix is to change your proxy to redirect any traffic from http://<your-ip>/ to https://your.domain.com/

For NGINX something like the following should work

    if ($host != your.domain.com) {
        return 301 https://your.domain.com$request_uri;
    }
3 years ago
SGaitskell wrote:
I believe this is caused by the image cache.

The first hit on your website via the ip address http://<your-ip>, after the cache is cleared, causes the images to be cached with the IP address in the URL, rather than the domain name.
Images then fail to load, as the SSL Certificate is for the https://your.domain.com/


The problem is mainly due to web robots/crawlers accessing your website by IP address using the DNS a record. Too many hits by these types of robots can intermittently cause this problem.

Without attempting to modifying the sourcecode, recompiling nopcommerce and deploy, you can do one of following to eliminate this issue:
- somehow block undesirable robots that access your website by IP
- change DNS records and remove the 'a' record and keep the cname record only if possible
3 years ago
SGaitskell wrote:
The fix is to change your proxy to redirect any traffic from http://<your-ip>/ to https://your.domain.com/

For NGINX something like the following should work

    if ($host != your.domain.com) {
        return 301 https://your.domain.com$request_uri;
    }

Actually using if statements is not a good idea according to nginx documentation https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/#using-if you should use different server directives.
The following example configuration is from a Ubuntu 18.04 VPS running nopcommerce 4.30, nginx 1.18.0, certbot (for Let's Encrypt SSL). It redirects http requests (non-www, www, ip) to https with www in front of the domain name and https (non-www, ip) to https with www in front of the domain name:
server {
    listen 80;
    server_name example.com www.example.com xxx.xxx.xxx.xxx;
    return 301 https://www.example.com$request_uri;
}

server {
    listen 443 ssl;
    server_name example.com xxx.xxx.xxx.xxx;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    return 301 https://www.example.com$request_uri;
}

server {
    server_name   www.example.com;
    location / {
        proxy_pass         http://localhost: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;
    }
    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

If you follow the configuration above, you should use https and www as your store url (Configuration -> Stores -> Store URL -> https://www.example.com/), otherwise the automatic scheduled tasks fail (System -> Schedule Tasks) .
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.