django - 未找到(通过 digitalocean、nginx、ubuntu、Gunicorn 部署)
问题描述
我尝试通过 digitalocean、nginx、ubuntu 和 Gunicorn 部署 Django。
我遵循了digitaloccean 提供的教程。在与 Gunicorn 绑定之前,一切都很好。
我能够使用运行“ manage.py runserver 0.0.0.0:8000
”并且能够在IP地址的8000端口上看到该网站;
但是,当我尝试跑步时gunicorn --bind 0.0.0.0:8000 biostar.wsgi
(virtualcrew) corey@crew:~/digitalocceancrew/digitalcrew$ gunicorn --bind 0.0.0.0:8000 biostar.wsgi
[2021-06-23 12:55:36 +0000] [134047] [INFO] Starting gunicorn 20.1.0
[2021-06-23 12:55:36 +0000] [134047] [INFO] Listening at: http://0.0.0.0:8000 (134047)
[2021-06-23 12:55:36 +0000] [134047] [INFO] Using worker: sync
[2021-06-23 12:55:36 +0000] [134049] [INFO] Booting worker with pid: 134049
,并再次尝试连接IP地址,出现404 not found错误。输出
但是当我试图跑sudo gunicorn --bind 0.0.0.0:8000 biostar.wsgi
(virtualcrew) corey@crew:~/digitalocceancrew/digitalcrew$ sudo gunicorn --bind 0.0.0.0:8000 biostar.wsgi
[2021-06-23 12:54:09 +0000] [134021] [INFO] Starting gunicorn 20.0.4
[2021-06-23 12:54:09 +0000] [134021] [INFO] Listening at: http://0.0.0.0:8000 (134021)
[2021-06-23 12:54:09 +0000] [134021] [INFO] Using worker: sync
[2021-06-23 12:54:09 +0000] [134023] [INFO] Booting worker with pid: 134023
celery error No module named 'django'
[2021-06-23 12:54:09 +0000] [134023] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/usr/lib/python3/dist-packages/gunicorn/workers/base.py", line 119, in init_process
self.load_wsgi()
File "/usr/lib/python3/dist-packages/gunicorn/workers/base.py", line 144, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/lib/python3/dist-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/lib/python3/dist-packages/gunicorn/app/wsgiapp.py", line 49, in load
return self.load_wsgiapp()
File "/usr/lib/python3/dist-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python3/dist-packages/gunicorn/util.py", line 383, in import_app
mod = importlib.import_module(module)
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/corey/digitalocceancrew/digitalcrew/biostar/wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ModuleNotFoundError: No module named 'django'
[2021-06-23 12:54:09 +0000] [134023] [INFO] Worker exiting (pid: 134023)
[2021-06-23 12:54:09 +0000] [134021] [INFO] Shutting down: Master
[2021-06-23 12:54:09 +0000] [134021] [INFO] Reason: Worker failed to boot.
我还尝试了 IP 地址的每个端口,但都没有工作。
这是的输出systemctl status gunicorn.service
● gunicorn.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/gunicorn.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2021-06-19 09:14:20 UTC; 4 days ago
TriggeredBy: ● gunicorn.socket
Main PID: 34545 (gunicorn)
Tasks: 4 (limit: 1136)
Memory: 111.6M
CGroup: /system.slice/gunicorn.service
├─34545 /home/corey/digitalocceancrew/virtualcrew/bin/python /home/corey/digitalocceancrew/virtualcrew/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock biostar.wsgi:application
├─34557 /home/corey/digitalocceancrew/virtualcrew/bin/python /home/corey/digitalocceancrew/virtualcrew/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock biostar.wsgi:application
├─34558 /home/corey/digitalocceancrew/virtualcrew/bin/python /home/corey/digitalocceancrew/virtualcrew/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock biostar.wsgi:application
└─34559 /home/corey/digitalocceancrew/virtualcrew/bin/python /home/corey/digitalocceancrew/virtualcrew/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock biostar.wsgi:application
Jun 23 11:59:20 crew gunicorn[34557]: WARNING 2021-06-23 07:59:20,623 log.log_response 224 Not Found: /.env
Jun 23 11:59:20 crew gunicorn[34557]: - - [23/Jun/2021:07:59:20 -0400] "GET /.env HTTP/1.0" 404 179 "-" "python-requests/2.25.1"
Jun 23 12:06:31 crew gunicorn[34558]: WARNING 2021-06-23 08:06:31,852 log.log_response 224 Not Found: /
Jun 23 12:06:31 crew gunicorn[34558]: - - [23/Jun/2021:08:06:31 -0400] "GET / HTTP/1.0" 404 179 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36"
Jun 23 12:24:40 crew gunicorn[34557]: WARNING 2021-06-23 08:24:40,352 log.log_response 224 Not Found: /.env
Jun 23 12:24:40 crew gunicorn[34557]: - - [23/Jun/2021:08:24:40 -0400] "GET /.env HTTP/1.0" 404 179 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36"
Jun 23 12:24:40 crew gunicorn[34558]: WARNING 2021-06-23 08:24:40,553 log.log_response 224 Not Found: /
Jun 23 12:24:40 crew gunicorn[34558]: - - [23/Jun/2021:08:24:40 -0400] "POST / HTTP/1.0" 404 179 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36"
Jun 23 12:24:54 crew gunicorn[34559]: WARNING 2021-06-23 08:24:54,081 log.log_response 224 Not Found: /
Jun 23 12:24:54 crew gunicorn[34559]: - - [23/Jun/2021:08:24:54 -0400] "GET / HTTP/1.0" 404 179 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36"
这是输出sudo journalctl -u gunicorn
(virtualcrew) corey@crew:~/digitalocceancrew/digitalcrew$ sudo journalctl -u gunicorn
-- Logs begin at Sun 2021-06-20 07:46:26 UTC, end at Wed 2021-06-23 12:51:37 UTC. --
Jun 20 07:46:26 crew gunicorn[34559]: WARNING 2021-06-20 03:46:26,682 log.log_response 224 Not Found: /MTI4LjE5OS45Mi45MS1wZGZfMjEudHh0.xml
Jun 20 07:46:26 crew gunicorn[34559]: - - [20/Jun/2021:03:46:26 -0400] "GET /MTI4LjE5OS45Mi45MS1wZGZfMjEudHh0.xml HTTP/1.0" 404 179 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
Jun 20 07:46:51 crew gunicorn[34557]: WARNING 2021-06-20 03:46:51,386 log.log_response 224 Not Found: /MTI4LjE5OS45Mi45MS0xMDUtcGRmLnR4dA==.xml
Jun 20 07:46:51 crew gunicorn[34557]: - - [20/Jun/2021:03:46:51 -0400] "GET /MTI4LjE5OS45Mi45MS0xMDUtcGRmLnR4dA==.xml HTTP/1.0" 404 179 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
Jun 20 09:04:48 crew gunicorn[34559]: WARNING 2021-06-20 05:04:48,093 log.log_response 224 Not Found: /.env
Jun 20 09:04:48 crew gunicorn[34559]: - - [20/Jun/2021:05:04:48 -0400] "GET /.env HTTP/1.0" 404 179 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36"
Jun 20 09:04:48 crew gunicorn[34557]: WARNING 2021-06-20 05:04:48,585 log.log_response 224 Not Found: /
Jun 20 09:04:48 crew gunicorn[34557]: - - [20/Jun/2021:05:04:48 -0400] "POST / HTTP/1.0" 404 179 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36"
Jun 20 09:24:00 crew gunicorn[34558]: WARNING 2021-06-20 05:24:00,154 log.log_response 224 Not Found: /_ignition/execute-solution
Jun 20 09:24:00 crew gunicorn[34558]: - - [20/Jun/2021:05:24:00 -0400] "GET /_ignition/execute-solution HTTP/1.0" 404 179 "-" "python-requests/2.18.4"
Jun 20 09:47:12 crew gunicorn[34557]: WARNING 2021-06-20 05:47:12,781 log.log_response 224 Not Found: /
Jun 20 09:47:12 crew gunicorn[34557]: - - [20/Jun/2021:05:47:12 -0400] "GET / HTTP/1.0" 404 179 "-" "-"
Jun 20 09:47:13 crew gunicorn[34559]: WARNING 2021-06-20 05:47:13,166 log.log_response 224 Not Found: /
Jun 20 09:47:13 crew gunicorn[34559]: - - [20/Jun/2021:05:47:13 -0400] "GET / HTTP/1.0" 404 179 "-" "Mozilla/5.0 (compatible; CensysInspect/1.1; +https://about.censys.io/)"
Jun 20 09:58:11 crew gunicorn[34558]: WARNING 2021-06-20 05:58:11,030 log.log_response 224 Not Found: /.env
Jun 20 09:58:11 crew gunicorn[34558]: - - [20/Jun/2021:05:58:11 -0400] "GET /.env HTTP/1.0" 404 179 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36"
Jun 20 09:58:11 crew gunicorn[34557]: WARNING 2021-06-20 05:58:11,217 log.log_response 224 Not Found: /
Jun 20 09:58:11 crew gunicorn[34557]: - - [20/Jun/2021:05:58:11 -0400] "POST / HTTP/1.0" 404 179 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36"
Jun 20 10:11:55 crew gunicorn[34559]: WARNING 2021-06-20 06:11:55,505 log.log_response 224 Not Found: /
Jun 20 10:11:55 crew gunicorn[34559]: - - [20/Jun/2021:06:11:55 -0400] "GET / HTTP/1.0" 404 179 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.106 Safari/>
Jun 20 10:40:41 crew gunicorn[34557]: WARNING 2021-06-20 06:40:41,937 log.log_response 224 Not Found: /.env
Jun 20 10:40:41 crew gunicorn[34557]: - - [20/Jun/2021:06:40:41 -0400] "GET /.env HTTP/1.0" 404 179 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36"
Jun 20 10:40:42 crew gunicorn[34558]: WARNING 2021-06-20 06:40:42,935 log.log_response 224 Not Found: /
Jun 20 10:40:42 crew gunicorn[34558]: - - [20/Jun/2021:06:40:42 -0400] "POST / HTTP/1.0" 404 179 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36"
Jun 20 11:38:28 crew gunicorn[34558]: WARNING 2021-06-20 07:38:28,734 log.log_response 224 Not Found: /MTI4LjE5OS45Mi45MS0zOC1wZGYudHh0.xml
Jun 20 11:38:28 crew gunicorn[34558]: - - [20/Jun/2021:07:38:28 -0400] "GET /MTI4LjE5OS45Mi45MS0zOC1wZGYudHh0.xml HTTP/1.0" 404 179 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
Jun 20 11:43:16 crew gunicorn[34559]: WARNING 2021-06-20 07:43:16,900 log.log_response 224 Not Found: /robots.txt
Jun 20 11:43:16 crew gunicorn[34559]: - - [20/Jun/2021:07:43:16 -0400] "GET /robots.txt HTTP/1.0" 404 179 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
Jun 20 11:43:17 crew gunicorn[34557]: WARNING 2021-06-20 07:43:17,763 log.log_response 224 Not Found: /
Jun 20 11:43:17 crew gunicorn[34557]: - - [20/Jun/2021:07:43:17 -0400] "GET / HTTP/1.0" 404 179 "-" "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"
Jun 20 11:46:49 crew gunicorn[34559]: WARNING 2021-06-20 07:46:49,299 log.log_response 224 Not Found: /MTI4LjE5OS45Mi45MS0zODFhbWNvOWkudHh0.xml
Jun 20 11:46:49 crew gunicorn[34559]: - - [20/Jun/2021:07:46:49 -0400] "GET /MTI4LjE5OS45Mi45MS0zODFhbWNvOWkudHh0.xml HTTP/1.0" 404 179 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
Jun 20 11:47:02 crew gunicorn[34557]: WARNING 2021-06-20 07:47:02,987 log.log_response 224 Not Found: /MTI4LjE5OS45Mi45MS03Zmh0c2VsODUudHh0.xml
Jun 20 11:47:02 crew gunicorn[34557]: - - [20/Jun/2021:07:47:02 -0400] "GET /MTI4LjE5OS45Mi45MS03Zmh0c2VsODUudHh0.xml HTTP/1.0" 404 179 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
Jun 20 11:52:56 crew gunicorn[34558]: WARNING 2021-06-20 07:52:56,575 log.log_response 224 Not Found: /MTI4LjE5OS45Mi45MS16c3FiMG12ZmMudHh0.xml
Jun 20 11:52:56 crew gunicorn[34558]: - - [20/Jun/2021:07:52:56 -0400] "GET /MTI4LjE5OS45Mi45MS16c3FiMG12ZmMudHh0.xml HTTP/1.0" 404 179 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
Jun 20 11:53:48 crew gunicorn[34558]: WARNING 2021-06-20 07:53:48,748 log.log_response 224 Not Found: /MTI4LjE5OS45Mi45MS1wZGZfMTM5LnR4dA==.xml
Jun 20 11:53:48 crew gunicorn[34558]: - - [20/Jun/2021:07:53:48 -0400] "GET /MTI4LjE5OS45Mi45MS1wZGZfMTM5LnR4dA==.xml HTTP/1.0" 404 179 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
Jun 20 11:56:02 crew gunicorn[34559]: WARNING 2021-06-20 07:56:02,167 log.log_response 224 Not Found: /boaform/admin/formLogin
Jun 20 11:56:02 crew gunicorn[34559]: - - [20/Jun/2021:07:56:02 -0400] "POST /boaform/admin/formLogin HTTP/1.0" 404 179 "http://128.199.92.91:80/admin/login.asp" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:71.0) Geck>
Jun 20 12:04:31 crew gunicorn[34558]: WARNING 2021-06-20 08:04:31,453 log.log_response 224 Not Found: /MTI4LjE5OS45Mi45MS1wZGZfMTM4LnR4dA==.xml
Jun 20 12:04:31 crew gunicorn[34558]: - - [20/Jun/2021:08:04:31 -0400] "GET /MTI4LjE5OS45Mi45MS1wZGZfMTM4LnR4dA==.xml HTTP/1.0" 404 179 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
Jun 20 12:05:44 crew gunicorn[34557]: WARNING 2021-06-20 08:05:44,775 log.log_response 224 Not Found: /mathematical_ideas_12th_edition_online_free.pdf
Jun 20 12:05:44 crew gunicorn[34557]: - - [20/Jun/2021:08:05:44 -0400] "GET /mathematical_ideas_12th_edition_online_free.pdf HTTP/1.0" 404 179 "-" "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKi>
Jun 20 12:13:36 crew gunicorn[34559]: WARNING 2021-06-20 08:13:36,178 log.log_response 224 Not Found: /MTI4LjE5OS45Mi45MS1kcXQ2Mm52YXMudHh0.xml
Jun 20 12:13:36 crew gunicorn[34559]: - - [20/Jun/2021:08:13:36 -0400] "GET /MTI4LjE5OS45Mi45MS1kcXQ2Mm52YXMudHh0.xml HTTP/1.0" 404 179 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
Jun 20 12:15:09 crew gunicorn[34559]: WARNING 2021-06-20 08:15:09,785 log.log_response 224 Not Found: /MTI4LjE5OS45Mi45MS1wZGZfMTc3LnR4dA==.xml
Jun 20 12:15:09 crew gunicorn[34559]: - - [20/Jun/2021:08:15:09 -0400] "GET /MTI4LjE5OS45Mi45MS1wZGZfMTc3LnR4dA==.xml HTTP/1.0" 404 179 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
Jun 20 12:17:00 crew gunicorn[34559]: WARNING 2021-06-20 08:17:00,000 log.log_response 224 Not Found: /
Jun 20 12:17:00 crew gunicorn[34559]: - - [20/Jun/2021:08:16:59 -0400] "GET / HTTP/1.0" 404 179 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36"
Jun 20 12:22:12 crew gunicorn[34559]: WARNING 2021-06-20 08:22:12,841 log.log_response 224 Not Found: /MTI4LjE5OS45Mi45MS1jcnUweW5kdjEudHh0.xml
Jun 20 12:22:12 crew gunicorn[34559]: - - [20/Jun/2021:08:22:12 -0400] "GET /MTI4LjE5OS45Mi45MS1jcnUweW5kdjEudHh0.xml HTTP/1.0" 404 179 "-" "Mozilla/5.0 (compatible; bingbot/2.0; +http://www.bing.com/bingbot.htm)"
Jun 20 12:27:35 crew gunicorn[34557]: WARNING 2021-06-20 08:27:35,621 log.log_response 224 Not Found: /
这是和的输出ls -l /run/gunicorn.sock
(netstat -tlpn | grep 'gunicorn'
第二个没有任何输出)
(virtualcrew) corey@crew:~/digitalocceancrew/digitalcrew$ sudo ls -l /run/gunicorn.sock
srw-rw-rw- 1 root root 0 Jun 19 09:03 /run/gunicorn.sock
(virtualcrew) corey@crew:~/digitalocceancrew/digitalcrew$ sudo netstat -tlpn | grep 'gunicorn'
(virtualcrew) corey@crew:~/digitalocceancrew/digitalcrew$
当我输入时sudo tail -f /var/log/nginx/error.log
,它开始运行并卡住了。(无输出)
(virtualcrew) corey@crew:~/digitalocceancrew/digitalcrew$ sudo tail -f /var/log/nginx/error.log
的输出sudo netstat -tulpn
(virtualcrew) corey@crew:~/digitalocceancrew/digitalcrew$ sudo netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 90046/nginx: master
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 559/systemd-resolve
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1163/sshd: /usr/sbi
tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN 4284/postgres
tcp6 0 0 :::80 :::* LISTEN 90046/nginx: master
tcp6 0 0 :::22 :::* LISTEN 1163/sshd: /usr/sbi
udp 0 0 127.0.0.53:53 0.0.0.0:* 559/systemd-resolve
我有以下问题:
- 什么可能导致此错误?
- 能在本地服务器上运行是否意味着错误不是源代码引起的?
- 我可以尝试什么来解决这个问题?
谢谢 !!!
解决方案
推荐阅读
- node.js - 如何使用excel4node在excel表格中写入数组
- python - 合并 pandas df 时出错。TypeError:(“'float'类型的对象没有len()”,'发生在索引D')
- javascript - 无法获取元素的属性
- xcode - 将 Xcode 项目 (Xcode 9) 添加到 Subversion (SVN)
- nativescript-vue - NativeScript-Vue - 从外部组件导航
- firebase - 不能有多个默认规则
- python - 熊猫数据框:根据另一列中的值替换多行
- matlab - 如何在 Matlab / Origin 上绘制不均匀间隔的数据?
- node.js - 如何修复“解析错误:保留关键字‘await’”
- java - Java 字符串是否根据它们的构造方式以不同的方式存储在堆中?