uwsgi+nginx Proxy Django cannot access static resources
- 2021-10-27 10:05:39
- OfStack
When deploying the uwsgi+nginx proxy Django, access is normal using uwsgi, but static resources cannot be accessed using the nginx proxy port.
Solution:
mod 755 /data/django/static -R
uwsgi configuration:
# uwsig Startup using a configuration file
[uwsgi]
# Root directory where the project is located
chdir=/data/django/dailyfresh
# Object of the specified project application, Different from the startup command --wsgi-filemysite/wsgi.py
#logsquery The name of your own application
module=dailyfresh.wsgi:application
#the local unix socket file than commnuincate to Nginx
# Specify sock The file path of, this sock The file will be in the nginx Adj. uwsgi_pass Configuration, used for nginx And uwsgi Communication
# Support ip+port Patterns and socket file Mode
#socket=/etc/uwsgi/uwsgi.sock
socket=127.0.0.1:9001
# Number of processes
processes = 8
# Each process worker Number
workers=5
procname-prefix-spaced=dailyfresh # uwsgi Process name prefix of
py-autoreload=1 # py File modification, automatic loading
# Specify IP Port, web Access portal
http=0.0.0.0:9000
# Start uwsgi User name and user group of
uid=root
gid=root
# Enable the main process
master=true
# Automatic removal unix Socket And pid File when the service stops
vacuum=true
# Serialize what is accepted, if possible
thunder-lock=true
# Enable threads
enable-threads=true
# Settings 1 A timeout is used to interrupt additional requests that exceed the server request limit
harakiri=30
# Set buffering
post-buffering=4096
# Setting the log directory
daemonize=/var/log/uwsgi/uwsgi.log
# uWSGI Process number storage
pidfile=/etc/uwsgi/uwsgi.pid
nginx configuration:
server {
listen 9002;
server_name 192.168.2.100;
access_log /var/log/test.log;
error_log /var/log/test.log;
charset utf-8;
client_max_body_size 100M;
location /static{
alias /data/django/dailyfresh/static;
}
location /media{
alias /data/django/dailyfresh/media;
}
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9001;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}