Solution to Django's inability to access static resources with uwsgi+nginx proxy

Solution to Django's inability to access static resources with uwsgi+nginx proxy

When deploying uwsgi+nginx proxy Django, access using uwsgi is normal, but static resources cannot be accessed when using nginx proxy port access.

Solution:

  • Check the nginx startup user and grant access to static resources to this user.
  • For example, my static resource directory is: /data/django/static
  • Empower: ch mod 755 /data/django/static -R

uwsgi configuration:

# uwsig starts using the configuration file [uwsgi]
# The root directory of the project is chdir=/data/django/dailyfresh
#Specify the application of the project, different from the startup command--wsgi-filemysite/wsgi.py
#logsquery your own application namemodule=dailyfresh.wsgi:application
#the local unix socket file than commnuincate to Nginx
#Specify the file path of sock. This sock file will be configured in uwsgi_pass of nginx for communication between nginx and uwsgi. #Support ip+port mode and socket file mode #socket=/etc/uwsgi/uwsgi.sock
socket=127.0.0.1:9001
# Number of processes processes = 8
# Number of workers per process workers=5
procname-prefix-spaced=dailyfresh # uwsgi process name prefix py-autoreload=1 # py file modification, automatic loading # Specify IP port, web access entry http=0.0.0.0:9000
# Start uwsgi's username and user group uid=root
gid=root
# Enable the master process master=true
# Automatically remove unix socket and pid file when the service stops vacuum=true
# Serialize received content, thunder-lock=true if possible
# Enable threads enable-threads=true
# Set a timeout to interrupt additional requests that exceed the server's request limit harakiri=30
# Set post-buffering=4096
# Set the log directory daemonize=/var/log/uwsgi/uwsgi.log
# uWSGI process number is stored in 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;
            }
}

This is the end of this article about the solution to the problem that uwsgi+nginx proxy Django cannot access static resources. For more related content about uwsgi+nginx proxy Django cannot access, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of the idea of ​​deploying Nginx+Uwsgi+Django project to the server
  • Django project uwsgi+Nginx nanny-level deployment tutorial implementation
  • Detailed deployment of Django uwsgi Nginx in production environment
  • Example of deploying Django project with uwsgi+nginx
  • Detailed explanation of Django+Uwsgi+Nginx to achieve production environment deployment
  • Django2+uwsgi+nginx is deployed online to the server Ubuntu16.04
  • Django + Uwsgi + Nginx to achieve production environment deployment method
  • Solve all the problems of deploying Django with nginx+uwsgi (summary)

<<:  Pure CSS to achieve cloudy weather icon effect

>>:  Solve the problem of MySQL Threads_running surge and slow query

Recommend

The difference and reasons between the MySQL query conditions not in and in

Write a SQL first SELECT DISTINCT from_id FROM co...

Vendor Prefix: Why do we need a browser engine prefix?

What is the Vendor Prefix? Vendor prefix—Browser ...

Detailed explanation of CocosCreator optimization DrawCall

Table of contents Preface What is DrawCall How do...

Detailed explanation of the binlog log analysis tool for monitoring MySQL: Canal

Canal is an open source project under Alibaba, de...

Detailed explanation of Linux lsof command usage

lsof (list open files) is a tool to view files op...

Abbreviation of HTML DOCTYPE

If your DOCTYPE is as follows: Copy code The code ...

Summary of pitfalls in importing ova files into vmware

Source of the problem As we all know, all network...

Detailed explanation of docker command to backup linux system

tar backup system sudo tar cvpzf backup.tgz --exc...

Tutorial on using portainer to connect to remote docker

Portainer is a lightweight docker environment man...

JavaScript to implement login form

This article example shares the specific code of ...

JavaScript to achieve lottery effect

This article shares the specific code of JavaScri...