I am using homebrew to start the nginx services.
Django project directory :
core (app)
main_app(app)
maps(app)
static → css folder, js folder etc
templates
manage.py
Steps :
- I add static url :
STATIC_URL = "/static/"
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
MEDIA_URL = "media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
- I then collect the static
nuntea@Zonunmawias-MacBook-Air vgt-bitmapper-portal-app % python3 manage.py collectstatic
184 static files copied to '/Users/nuntea/Documents/Vasundhara Geo technology/vgt-bitmapper-portal-app/staticfiles'.
-
I add the following server to
a. /etc/nginx/sites-enabled/django-app.conf b. /opt/homebrew/etc/nginx/nginx.conf (After adding the new server, there are two server)
server {
listen 80;
server_name _;
location /static/ {
alias '/Users/nuntea/Documents/Vasundhara Geo technology/vgt-bitmapper-portal-app/staticfiles/';
}
location / {
proxy_pass http://127.0.0.1:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Here are some further information :
nuntea@Zonunmawias-MacBook-Air vgt-bitmapper-portal-app % brew services list
Name Status User File
nginx started nuntea ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
nginx -t
nginx: the configuration file /opt/homebrew/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /opt/homebrew/etc/nginx/nginx.conf test is successful
nuntea@Zonunmawias-MacBook-Air vgt-bitmapper-portal-app % cat /opt/homebrew/var/log/nginx/error.log
No error printed
sudo lsof -i :8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 3926 nuntea 7u IPv4 0xb41b860f0985e595 0t0 TCP *:http-alt (LISTEN)
nginx 3933 nuntea 7u IPv4 0xb41b860f0985e595 0t0 TCP *:http-alt (LISTEN)
When I run the server :
python3 manage.py runserver
[01/Feb/2024 12:43:05] "GET /core/login-user/?next=/ HTTP/1.1" 200 1801
[01/Feb/2024 12:43:05] "GET /static/bootstrap_css/bootstrap.min.css HTTP/1.1" 404 179
[01/Feb/2024 12:43:05] "GET /static/custom_css/base.css HTTP/1.1" 404 179
[01/Feb/2024 12:43:05] "GET /static/jquery_js/jquery-3.6.4.min.js HTTP/1.1" 404 179
[01/Feb/2024 12:43:05] "GET /static/bootstrap_js/bootstrap.min.js HTTP/1.1" 404 179
It couldn’t find the css etc