Saleor: Static for production don't work

Created on 1 Jan 2018  ·  21Comments  ·  Source: mirumee/saleor

I try to deploy saleor in production mode and doing all as describe in docs - https://saleor.readthedocs.io/en/latest/deploy.html, but have 404 for all static
I used it with local docker, with docker-compose. I tried to collectstatic before building and inside container - result the same.
I use env DEBUG = False.

All 21 comments

With DEBUG enabled, Django serves static files for you. If you disable it, your production server should take care of it.
You can use Whitenoise as in Heroku's guide

But usually our choice is AWS, we have integration guide for it, I tested it last week, works out of the box™ Just remember to configure bucket policy accordingly.

If you decide to use external storage to serve statics (eg. AWS) you need to set STATIC_URL env variable, as used in https://github.com/mirumee/saleor/blob/master/webpack.config.js#L18

Thanks, @Pacu2, i'll try to use env STATIC_URL and will write results

I use Whitenoise, it works good for me.

@yevheniidehtiar what exactly you did to get whitenoise to work?

Am using was AWS S3 Bucket, set DEBUG=False, STATIC_URL=/static/, run collectstatic, still getting 404 for my css files.

I got it working, had to manually set STATIC_URL in webpack.config for production.

@maragh do you get product images for example? If so, it works.
Now, what you want, is to get the compiled assets to be acceded, for that, you will need to recompile the assets and tell it that you want it to use the S3 bucket. Here is how to proceed:

  1. Make sure your webpack.config.js file is up to date. But, if you are not using the master branch, use this version webpack.config.js as the local files will not be compatible with the latest master (<= 2018.07);
  2. You need to set STATIC_URL to your S3 bucket URL (to the parent directory of assets);
  3. Run npm run build-assets --production;
  4. Make sure your S3 assets files were compiled using --production, if not, re-run collectstatics to update the S3 bucket;
  5. Restart Saleor.

The reason is that by default the assets file are compiled to look into the local storage under /static/assets/ unless specified.

Was too slow to answer :wink:

Thanks for the reply man!! and many thanks for that detail example!

With DEBUG enabled, Django serves static files for you. If you disable it, your production server should take care of it.
You can use Whitenoise as in Heroku's guide

But usually our choice is AWS, we have integration guide for it, I tested it last week, works out of the box™ Just remember to configure bucket policy accordingly.

If you decide to use external storage to serve statics (eg. AWS) you need to set STATIC_URL env variable, as used in https://github.com/mirumee/saleor/blob/master/webpack.config.js#L18

I am little bit confusing why using Whitenoise is still recomended while on issues#465 it has been decided to replace Gunicorn and Whitenoise by uWsgi's static-map. Would you mind to give me a clue on this?

Hi! You should probably open an issue about that, I'm not sure that the people that know the answer will see your question as it is a resolved issue, so they are most of the time not opened in the notifications 👍

Hi! I'm trying to deploy Saleor on DigitalOcean, Ubuntu16.04 using Nginx+Gunicorn+supervisor. When DEBUG=True shop is displayed well in the browser. But when DEBUG=False, nothing is displayed (browser says Unable to connect). I know that if DEBUG is False nginx must serve my static files. But I'm trying to test whether Gunicorn can serve Saleor application by running the following command: gunicorn saleor.wsgi:application --bind :8001. So if DEBUG is True - Gunicorn starts and site works on browser, but if DEBUG is False - doesn't. I want to store my static files on server under saleor/static. Is there any way to fix my issue?

Hi! I'm trying to deploy Saleor on DigitalOcean, Ubuntu16.04 using Nginx+Gunicorn+supervisor. When DEBUG=True shop is displayed well in the browser. But when DEBUG=False, nothing is displayed (browser says Unable to connect). I know that if DEBUG is False nginx must serve my static files. But I'm trying to test whether Gunicorn can serve Saleor application by running the following command: gunicorn saleor.wsgi:application --bind :8001. So if DEBUG is True - Gunicorn starts and site works on browser, but if DEBUG is False - doesn't. I want to store my static files on server under saleor/static. Is there any way to fix my issue?

No, even I couldn't find a solution.

Hi! I'm trying to deploy Saleor on DigitalOcean, Ubuntu16.04 using Nginx+Gunicorn+supervisor. When DEBUG=True shop is displayed well in the browser. But when DEBUG=False, nothing is displayed (browser says Unable to connect). I know that if DEBUG is False nginx must serve my static files. But I'm trying to test whether Gunicorn can serve Saleor application by running the following command: gunicorn saleor.wsgi:application --bind :8001. So if DEBUG is True - Gunicorn starts and site works on browser, but if DEBUG is False - doesn't. I want to store my static files on server under saleor/static. Is there any way to fix my issue?

No, even I couldn't find a solution.

Hi, when I commented those two lines in settings.py:
if ENABLE_SSL:
SECURE_SSL_REDIRECT = not DEBUG
this solved my problem.

Hi! I'm trying to deploy Saleor on DigitalOcean, Ubuntu16.04 using Nginx+Gunicorn+supervisor. When DEBUG=True shop is displayed well in the browser. But when DEBUG=False, nothing is displayed (browser says Unable to connect). I know that if DEBUG is False nginx must serve my static files. But I'm trying to test whether Gunicorn can serve Saleor application by running the following command: gunicorn saleor.wsgi:application --bind :8001. So if DEBUG is True - Gunicorn starts and site works on browser, but if DEBUG is False - doesn't. I want to store my static files on server under saleor/static. Is there any way to fix my issue?

No, even I couldn't find a solution.

Hi, when I commented those two lines in settings.py:
if ENABLE_SSL:
SECURE_SSL_REDIRECT = not DEBUG
this solved my problem.

@ruszhov no, didn't work and following errors were generated

WARNING django.request Not Found: /static/assets/storefront.de2a8e980125d75f9a6c.js [PID:9:Thread-16]
web_1 | WARNING django.request Not Found: /static/assets/storefront.de2a8e980125d75f9a6c.js [PID:9:Thread-16]
web_1 | WARNING django.server "GET /static/assets/storefront.de2a8e980125d75f9a6c.js HTTP/1.1" 404 30682 [PID:9:Thread-16]
web_1 | WARNING django.server "GET /static/assets/storefront.de2a8e980125d75f9a6c.js HTTP/1.1" 404 30682 [PID:9:Thread-16]
web_1 | WARNING django.server "GET /static/assets/storefront.de2a8e980125d75f9a6c.js HTTP/1.1" 404 30682 [PID:9:Thread-16]
web_1 | ----------------------------------------
web_1 | Exception happened during processing of request from ('45.127.138.7', 47237)
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.7/socketserver.py", line 650, in process_request_thread
web_1 | self.finish_request(request, client_address)
web_1 | File "/usr/local/lib/python3.7/socketserver.py", line 360, in finish_request
web_1 | self.RequestHandlerClass(request, client_address, self)
web_1 | File "/usr/local/lib/python3.7/socketserver.py", line 720, in __init__
web_1 | self.handle()
web_1 | File "/usr/local/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 171, in handle
web_1 | self.handle_one_request()
web_1 | File "/usr/local/lib/python3.7/site-packages/django/core/servers/basehttp.py", line 179, in handle_one_request
web_1 | self.raw_requestline = self.rfile.readline(65537)
web_1 | File "/usr/local/lib/python3.7/socket.py", line 589, in readinto
web_1 | return self._sock.recv_into(b)
web_1 | ConnectionResetError: [Errno 104] Connection reset by peer
web_1 | ----------------------------------------
web_1 | WARNING django.request Not Found: /static/favicons/favicon-16x16.png [PID:9:Thread-23]
web_1 | WARNING django.request Not Found: /static/favicons/favicon-16x16.png [PID:9:Thread-23]
web_1 | WARNING django.server "GET /static/favicons/favicon-16x16.png HTTP/1.1" 404 29992 [PID:9:Thread-23]
web_1 | WARNING django.server "GET /static/favicons/favicon-16x16.png HTTP/1.1" 404 29992 [PID:9:Thread-23]

@mayank-budhiraja have you tried regenerate assets?
npm run build-assets --production

@mayank-budhiraja have you tried regenerate assets?
npm run build-assets --production

@ruszhov I am deploying using docker. Do I have to rebuild the image and then run docker-compose onto the server?

@mayank-budhiraja have you tried regenerate assets?
npm run build-assets --production

@ruszhov I am deploying using docker. Do I have to rebuild the image and then run docker-compose onto the server?

I think you should try collect static. I don't use docker, иге I think there might be something like this: docker-compose run --rm web python3 manage.py collectstatic
https://saleor.readthedocs.io/en/latest/customization/docker.html

Yes! I did this only but _collecstatic_ did not copy any files. I check the containers all files are present but application is still not getting the static files.

Yes! I did this only but _collecstatic_ did not copy any files. I check the containers all files are present but application is still not getting the static files.

In production mode nginx have to take care of the static files. Check nginx settings.

Can't find anything, all settings are correct.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

damianarechar picture damianarechar  ·  3Comments

gComet picture gComet  ·  3Comments

NumanIjaz picture NumanIjaz  ·  3Comments

maltitco picture maltitco  ·  3Comments

8BitAce picture 8BitAce  ·  4Comments