I want to deploy an old Django app, that works locally with Django 2.2.
This is what I did:

  • created Django app, deleted new Django version, installed 2.2
  • deleted default project folder, uploaded my own
  • adapted the folder name in uwsgi.ini
  • started and stopped the app
(env) [watchduck@opal9 wdnet_brainball3]$ ./start
[uWSGI] getting INI configuration from /home/watchduck/apps/wdnet_brainball3/uwsgi.ini
Started uWSGI for wdnet_brainball3.

But when I go to https://bb3.watchduck.net/ I get a 502 page.

The error.log of the site contains lines like this one:

2024/04/06 19:27:27 [error] 196434#196434: *262647988 connect() failed (111: Connection refused) while connecting to upstream, client: 87.181.191.124, server: bb3.watchduck.net, request: "GET / HTTP/2.0", upstream: "http://127.0.0.1:17000/", host: "bb3.watchduck.net"

In the uwsgi.log of the app I find:

*** Starting uWSGI 2.0.24 (64bit) on [Sat Apr  6 19:32:01 2024] ***
compiled with version: 11.2.1 20220127 (Red Hat 11.2.1-9) on 06 April 2024 19:07:15
os: Linux-3.10.0-1160.90.1.el7.x86_64 #1 SMP Thu May 4 15:21:22 UTC 2023
nodename: opal9.opalstack.com
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 32
current working directory: /home/watchduck
writing pidfile to /home/watchduck/apps/wdnet_brainball3/tmp/uwsgi.pid
detected binary path: /home/watchduck/apps/wdnet_brainball3/env/bin/uwsgi
your processes number limit is 4096
your memory page size is 4096 bytes
detected max file descriptor number: 4096
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
probably another instance of uWSGI is running on the same address (127.0.0.1:27697).
bind(): Address already in use [core/socket.c line 769]

(My settings.py currently uses DEBUG = True and ALLOWED_HOSTS = ['*'].)

What should I do?

  • sean replied to this.

    Watchduck I checked your apps and from what I can see you've copied your uwsgi.ini from a different app without updating the port to match the new app.

    To correct the problem edit the http-socket line in uwsgi.ini to use the correct port. Your apps' port assignments are listed at https://my.opalstack.com/apps/.

    Aside: I generally advise against using your actual shell user names, app names, port assignments, etc here in the public forum. Feel free to email that info to our support team in the future.

    Yes, that solved it. (And a correction to the paths in uwsgi.ini.)

    @sean There is still one weird thing. I would like to change DEBUG and ALLOWED_HOSTS to their production values.
    But when I change DEBUG to False, my static directory (i.e. styles and favicon) can not be accessed anymore.
    (I was not aware that DEBUG can do anything like that. Is this somehow less weird than it seems to me?)

    The following two lines are from the app's uwsgi.log. The first one with debug true, the second with false:

    [pid: 84231|app: 0|req: 2/2] 127.0.0.1 () {58 vars in 1058 bytes} [Sat Apr  6 20:44:09 2024] GET /static/app/style.css => generated 2387 bytes in 6 msecs via sendfile() (HTTP/1.1 200) 4 headers in 140 bytes (0 switches on core 1)
    
    [pid: 97047|app: 0|req: 2/2] 127.0.0.1 () {58 vars in 1058 bytes} [Sat Apr  6 20:48:15 2024] GET /static/app/style.css => generated 77 bytes in 1 msecs (HTTP/1.1 404) 3 headers in 100 bytes (1 switches on core 1)

    I have left it false for now. ALLOWED_HOSTS is still ['*'].
    This is how the page looks: https://bb3.watchduck.net/y5,y4,y3,w13,y1,w2,y12,y11,w10,w6,w7,w8,w9
    The styles should be here: https://bb3.watchduck.net/static/app/style.css

    • sean replied to this.

      sean Oops ... must be in the top 10 of the Django FAQ.

      To create a separate static app seems like the right thing for a website with photos etc.
      But just to deliver a CSS file and a favicon that is probably overkill.
      I chose instead to let Django handle this small task:

      My static files are in proj/app/static, so that is what I added in STATICFILES_DIRS in settings.py:

      STATIC_URL = '/static/'
      STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
      STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'app', 'static') ]

      python manage.py collectstatic creates the assets folder. (I created it locally, and then copied it to the server.)

      proj/proj/urls.py must be changed. These imports are needed:

      from django.urls import re_path
      from django.views.static import serve
      from django.conf import settings

      And this must be added to urlpatterns:

          re_path(
              r'^static/(?P<path>.*)$',
              serve,
              {'document_root': settings.STATIC_ROOT}
          )

      Works as expected 🙂
      https://old-brainball.watchduck.net/w1,y13,w3,w9,y5,y4,y8,y7,y6,w2,y12,y11,w10

      Mastodon