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 the static and media URL and path
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
STATIC_URL = '/static/'
STATIC_ROOT = '/Users/nuntea/Documents/Vasundhara Geo technology/vgt-bitmapper-portal-app/staticfiles/'
MEDIA_URL = '/media/'
MEDIA_ROOT = '/Users/nuntea/Documents/Vasundhara Geo technology/vgt-bitmapper-portal-app/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
server {
listen 8080;
server_name _;
location /static/ {
alias /Users/nuntea/Documents/Vasundhara\ Geo\ technology/vgt-bitmapper-portal-app/staticfiles/;
}
location /media/ {
alias /Users/nuntea/Documents/Vasundhara\ Geo\ technology/vgt-bitmapper-portal-app/media/;
}
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;
}
}
to the config file
sudo nano /opt/homebrew/etc/nginx/nginx.conf
The nginx.conf file (without comment):
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server {
listen 8080;
server_name _;
location /static/ {
alias /Users/nuntea/Documents/Vasundhara\ Geo\ technology/vgt-bitmapper-portal-app/staticfiles/;
}
location /media/ {
alias /Users/nuntea/Documents/Vasundhara\ Geo\ technology/vgt-bitmapper-portal-app/media/;
}
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;
}
}
include servers/*;
}
Here are some further information :
nuntea@Zonunmawias-MacBook-Air vgt-bitmapper-portal-app % 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
2024/02/01 18:45:38 [notice] 27654#0: signal process started
2024/02/01 18:52:33 [notice] 28151#0: signal process started
2024/02/01 18:54:08 [notice] 28392#0: signal process started
2024/02/01 18:57:44 [notice] 28474#0: signal process started
nuntea@Zonunmawias-MacBook-Air vgt-bitmapper-portal-app % sudo lsof -i :8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 27986 nuntea 6u IPv4 0xb41b860f093f6c3d 0t0 TCP *:http-alt (LISTEN)
nginx 28476 nuntea 6u IPv4 0xb41b860f093f6c3d 0t0 TCP *:http-alt (LISTEN)
Django start runserver
nuntea@Zonunmawias-MacBook-Air vgt-bitmapper-portal-app % python3 manage.py runserver
[01/Feb/2024 23:39:54] "GET / HTTP/1.1" 302 0
[01/Feb/2024 23:39:55] "GET /core/login-user/?next=/ HTTP/1.1" 200 1801
[01/Feb/2024 23:39:55] "GET /static/custom_css/base.css HTTP/1.1" 404 179
[01/Feb/2024 23:39:55] "GET /static/jquery_js/jquery-3.6.4.min.js HTTP/1.1" 404 179
[01/Feb/2024 23:39:55] "GET /static/bootstrap_css/bootstrap.min.css HTTP/1.1" 404 179
[01/Feb/2024 23:39:55] "GET /static/bootstrap_js/bootstrap.min.js HTTP/1.1" 404 179