該賞金到期in 4天。這個問題的答案有資格獲得 50聲望獎勵。 user8758206正在尋找信譽良好的來源的答案。
我正在嘗試按照以下步驟部署我的第一個 django 應用程式。我遇到的問題是,出于某種原因,uwsgi --emperor venv/vassals/ --uid www-data --gid www-data在激活后運行venv似乎只是洗掉了.sock我的根目錄中的檔案。我認為這是導致問題的原因,因為在/var/log/nginx/error.log建議處查看 nginx 日志:
2021/10/11 22:09:57 [crit] 4281#4281: *6 connect() to unix:///var/www/dolphin/dolphin.sock failed (2: No such file or directory) while connecting to upstream, client: 81.102.82.13, server: example.com, request: "GET /favicon.ico HTTP/2.0", upstream: "uwsgi://unix:///var/www/dolphin/dolphin.sock:", host: "example.com", referrer: "https://example.com/
這是我在 /etc/nginx/sites-available 中的組態檔(符號鏈接到啟用站點):
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
# the upstream component nginx needs to connect to
upstream django {
server unix:///var/www/dolphin/dolphin.sock;
#server unix:/var/www/dolphin/dolphin.sock;
}
# configuration of the server
server {
listen 443 ssl;
server_name example.com;
charset utf-8;
# max upload size
client_max_body_size 75M;
# Django media and static files
location /media {
alias /var/www/dolphin/app/media;
}
location /static {
alias /var/www/dolphin/app/static;
}
# Send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /var/www/dolphin/uwsgi_params;
}
}
我的 dolphin_uwsgi.ini 檔案:
[uwsgi]
# full path to Django project's root directory
chdir = /var/www/dolphin/
# Django's wsgi file
module = /var/www/dolphin/app/app/wsgi.py
# full path to python virtual env
home = /var/www/dolphin/venv/
# enable uwsgi master process
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
socket = /var/www/dolphin/dolphin.sock
# socket permissions
chmod-socket = 666
# clear environment on exit
vacuum = true
# daemonize uwsgi and write messages into given log
daemonize = /var/www/dolphin/uwsgi-emperor.log
I keep on getting an internal server error whenever loading the site in a browser for some reason (that is, after activating my venv and running uwsgi --emperor venv/vassals/ --uid www-data --gid www-data ) and I don't know why as the instructor seems to do it the same way as I am but it works for him.
Can anyone offer any insight here? Thank you
In case it might help, here's some of the potentially relevant parts of settings.py:
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
ALLOWED_HOSTS = ['example.com']
WSGI_APPLICATION = 'app.wsgi.application'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'app/static')
]
MEDIA_URL = '/images/'
UPDATE:
Generating the socket file with uwsgi --socket dolphin.sock --module app/app/wsgi.py also returns ModuleNotFoundError: No module named 'app/app/wsgi unable to load app 0 (mountpoint='') (callable not found or import error) *** no app loaded. going in full dynamic mode ***'- I think it's because the app is called app - my file structure to wsgi.py is dolphin/app/app/wsgi.py, but even trying this fails: uwsgi --socket dolphin.sock --module /var/www/dolphin/app/app/wsgi.py
I think it might be because I called it 'app' like this post, but that uses Flask, not Django: Flask and uWSGI - unable to load app 0 (mountpoint='') (callable not found or import error)
我很困惑 tbh,不知道我需要改變什么,也不知道傳遞給這個命令的路徑是什么:uwsgi --socket dolphin.sock --module app/app/wsgi --chmod-socket=666- 我不相信這app/app/wsgi是正確的路徑,盡管它看起來應該是正確的。
檔案夾結構:
海豚:
- 自述檔案
- dolphin.sock(在運行該容易出錯的命令后生成)
- 要求.txt
- uwsgi_params
- 應用程式
- 資料庫.sqlite3
- 管理檔案
- 應用程式
- 初始化.py
- 快取
- asgi.py
- 設定.py
- 網址.py
- wsgi.py
- 媒體
- 靜止的
- 還有其他模塊
- dolphin_uwsgi.ini
- uwsgi-emperor.log
- venv
wsgi.py:
"""
WSGI config for app project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')
application = get_wsgi_application()
的完整輸出uwsgi --socket dolphin.sock --module app/app/wsgi --chmod-socket=666:
machine: aarch64
clock source: unix
detected number of CPU cores: 4
current working directory: /var/www/dolphin
detected binary path: /var/www/dolphin/venv/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 3244
your memory page size is 4096 bytes
detected max file descriptor number: 1024
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uwsgi socket 0 bound to UNIX address dolphin.sock fd 3
Python version: 3.8.10 (default, Sep 28 2021, 16:10:42) [GCC 9.3.0]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0xaaaaf5c10c10
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72904 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
ModuleNotFoundError: No module named 'app/app/wsgi'
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 129638, cores: 1)
uj5u.com熱心網友回復:
# full path to Django project's root directory chdir = /var/www/dolphin/ # Django's wsgi file module = /var/www/dolphin/app/app/wsgi.py
由于 manage.py 位于 dolphin/app 中,因此它是您的 Django 專案的根目錄。
# full path to Django project's root directory
chdir = /var/www/dolphin/app
# Django's wsgi file
wsgi-file = app/wsgi.py
在命令列上: uwsgi --socket dolphin.sock --chdir app --wsgi-file app/wsgi.py
參考:https : //uwsgi-docs.readthedocs.io/en/latest/WSGIquickstart.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/315300.html
