Browse Source

fix static root folder

subDesTagesMitExtraKaese 2 years ago
parent
commit
0787ce229f
5 changed files with 58 additions and 13 deletions
  1. 4 1
      .dockerignore
  2. 1 2
      Dockerfile
  3. 50 7
      nginx.conf
  4. 2 2
      production.sh
  5. 1 1
      project/settings.py

+ 4 - 1
.dockerignore

@@ -1 +1,4 @@
-data/
+/data/
+/static/
+/*.yml
+/*.sqlite3

+ 1 - 2
Dockerfile

@@ -14,8 +14,7 @@ ARG CACHEBUST
 RUN pip install -r requirements.txt && apt-get purge -y libmariadb-dev gcc
 
 COPY . /app/
-RUN cp ./nginx.conf /etc/nginx/conf.d/default.conf && \
-  python manage.py collectstatic --noinput
+RUN python manage.py collectstatic --noinput
 
 EXPOSE 8000
 

+ 50 - 7
nginx.conf

@@ -1,7 +1,50 @@
-server {
-  listen 80;
-  server_name  localhost;
-  location ^/static {
-    try_files $uri $uri/ =404;
-  }
-}
+user www-data;
+worker_processes auto;
+pid /run/nginx.pid;
+include /etc/nginx/modules-enabled/*.conf;
+
+events {
+    worker_connections 768;
+    # multi_accept on;
+}
+
+http {
+
+    ##
+    # Basic Settings
+    ##
+
+    sendfile on;
+    tcp_nopush on;
+    types_hash_max_size 2048;
+    # server_tokens off;
+
+    # server_names_hash_bucket_size 64;
+    # server_name_in_redirect off;
+
+    include /etc/nginx/mime.types;
+    default_type application/octet-stream;
+
+    ##
+    # Logging Settings
+    ##
+
+    access_log /dev/stdout;
+    error_log /dev/stdout;
+
+    ##
+    # Gzip Settings
+    ##
+
+    gzip on;
+
+    server {
+        listen 80;
+        root /static;
+        server_name  localhost;
+        location ^/static {
+            try_files $uri $uri/ =404;
+        }
+    }
+}
+

+ 2 - 2
production.sh

@@ -1,5 +1,5 @@
 #!/bin/sh
 python3 manage.py migrate
-python3 manage.py collectstatic --noinput
-chown -R 101:101 /static
+
+nginx -c /app/nginx.conf &
 gunicorn --bind :8000 --workers 2 project.wsgi:application --timeout 120

+ 1 - 1
project/settings.py

@@ -143,7 +143,7 @@ USE_TZ = True
 
 STATIC_URL = 'static/'
 
-STATIC_ROOT = '/etc/nginx/html/static'
+STATIC_ROOT = '/static/static'
 
 # Default primary key field type
 # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field