Hi Johnf,

Subject: Nginx + Gunicorn + Django Example

For a website using Nginx + Gunicorn + Django, try using STATIC_ROOT along
with the following settings.

If you login as user z, then usually your web project would be
set up in a path like /home/z/pesweb/
Note: The folder, pes_django1.11, seems out of place. Is it your
virtual environment? Usually your virtual environment would be
in a path like /home/z/pesweb/web_env/ Your specific folder setup
affects your gunicorn and nginx definitions (see below).

# If your website can be browsed at http://www.pesweb.com and
# your static files are browser-accessible at
# http://www.pesweb.com/static/ then your STATIC URL is /static/
STATIC_URL = '/static/'

# If you choose to keep the out-of-place folder, pes_django1.11, then
# STATIC_ROOT = '/home/z/pes_django1.11/pesweb/static/' This is not
# recommended since it seems to complicate things without any advantage.
#
# Absolute path to the directory static files should be collected to.
STATIC_ROOT = '/home/z/pesweb/static/'

And, your nginx definition might be like the following one:
server {
listen 80;
server_name pesweb.com www.pesweb.com;

# Give a blank page if browsing the IP.
root /var/www/html;

# Only static files need to be browser-accessible.
location /static/ {
root /home/z/pesweb
try_files $uri $uri/ =404;
}
}

And, your gunicorn definition might be like the following one:
[Unit]
Description=gunicorn-pesweb daemon
After=network.target

[Service]
User=z
Group=www-data
WorkingDirectory=/home/z/pesweb
ExecStart=/home/z/pesweb/web_env/bin/gunicorn --bind 
unix:/home/z/pesweb/pesweb.sock pesweb.wsgi:application

[Install]
WantedBy=multi-user.target

Hope this helps!

Cheers,
Carl

-------- Original Message --------
Subject: trouble with setting static for img and css
Local Time: May 11, 2017 8:28 AM
UTC Time: May 11, 2017 12:28 PM
From: jo...@jfcomputer.com
To: Django users <django-users@googlegroups.com>

Hi folks,

I have researched this issue and I know all I have to do is read the
doc's. But I can seem to get the correct path working to allow the
website to find the correct files in my Media,CSS and JS folders.

I'm using 1.11.x and have the following setup in OS file system.

I have set DEBUG = True

/z/pes_django1.11/pesweb/ is where my manage.py is located - it runs
just fine.

my files are in

/z/pes_django1.11/pesweb/static/static/css/ - this of course is for CSS

/z/pes_django1.11/pesweb/static/static/js/ -this of course is for JS

/z/pes_django1.11/pesweb/static/static/img/ -this of course is for
images like favicon.ico

In my settings.py file I have tried many combinations such as:

STATIC_URL = '/pesweb/static/static/'

STATIC_URL = '/static/static/'

STATIC_URL = '/pesweb/static/'

So would some kind soul please tell me what I need in STATIC_URL, and
MEDIA_URL.

Thanks in advance,

Johnf

--
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/4bf10da8-e78b-147c-78dd-0d4206143ba9%40jfcomputer.com.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/rCHl4oSoLaOBzbUogxAt29ZjbGHEYDLuM9t2ez2SvTwoUN9Iy_r7hM3xknWkUy4HZQZN8vm8aSAZiVMr4SVffB9wh--MLuXi8xzOw9GXIiM%3D%40nexuspro.ca.
For more options, visit https://groups.google.com/d/optout.

Reply via email to