django - Gunicorn 정적 파일 읽기 오류
점프 투 장고를 진행하던 중 구니콘을 이용해도 파이보에 정적 파일들이 적용되지 않기에 질문 드립니다.
(mysite) ubuntu@cloudkettle:~/projects/mysite$ sudo systemctl status mysite.service
● mysite.service - gunicorn daemon
Loaded: loaded (/etc/systemd/system/mysite.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2022-09-26 17:31:15 KST; 6min ago
Main PID: 21679 (gunicorn)
Tasks: 3 (limit: 1143)
Memory: 70.3M
CPU: 730ms
CGroup: /system.slice/mysite.service
├─21679 /home/ubuntu/venvs/mysite/bin/python3 /home/ubuntu/venvs/mysite/bin/gunicorn --workers 2 --bind unix:/tmp/gunicorn.sock config.wsgi:application
├─21681 /home/ubuntu/venvs/mysite/bin/python3 /home/ubuntu/venvs/mysite/bin/gunicorn --workers 2 --bind unix:/tmp/gunicorn.sock config.wsgi:application
└─21682 /home/ubuntu/venvs/mysite/bin/python3 /home/ubuntu/venvs/mysite/bin/gunicorn --workers 2 --bind unix:/tmp/gunicorn.sock config.wsgi:application
Sep 26 17:31:15 cloudkettle systemd[1]: mysite.service: Failed with result 'exit-code'.
Sep 26 17:31:15 cloudkettle systemd[1]: Stopped gunicorn daemon.
Sep 26 17:31:15 cloudkettle systemd[1]: mysite.service: Consumed 14.070s CPU time.
Sep 26 17:31:15 cloudkettle systemd[1]: Started gunicorn daemon.
Sep 26 17:31:15 cloudkettle gunicorn[21679]: [2022-09-26 17:31:15 +0900] [21679] [INFO] Starting gunicorn 20.1.0
Sep 26 17:31:15 cloudkettle gunicorn[21679]: [2022-09-26 17:31:15 +0900] [21679] [INFO] Listening at: unix:/tmp/gunicorn.sock (21679)
Sep 26 17:31:15 cloudkettle gunicorn[21679]: [2022-09-26 17:31:15 +0900] [21679] [INFO] Using worker: sync
Sep 26 17:31:15 cloudkettle gunicorn[21681]: [2022-09-26 17:31:15 +0900] [21681] [INFO] Booting worker with pid: 21681
Sep 26 17:31:15 cloudkettle gunicorn[21682]: [2022-09-26 17:31:15 +0900] [21682] [INFO] Booting worker with pid: 21682
아래는 /var/log/syslog 파일의 26일 분입니다
Sep 26 00:17:01 cloudkettle CRON[20724]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Sep 26 01:08:24 cloudkettle systemd[1]: Starting Daily man-db regeneration...
Sep 26 01:08:25 cloudkettle systemd[1]: man-db.service: Deactivated successfully.
Sep 26 01:08:25 cloudkettle systemd[1]: Finished Daily man-db regeneration.
Sep 26 01:17:01 cloudkettle CRON[20801]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Sep 26 02:14:39 cloudkettle systemd[1]: Starting Ubuntu Advantage Timer for running repeated jobs...
Sep 26 02:14:39 cloudkettle systemd[1]: ua-timer.service: Deactivated successfully.
Sep 26 02:14:39 cloudkettle systemd[1]: Finished Ubuntu Advantage Timer for running repeated jobs.
Sep 26 02:17:01 cloudkettle CRON[20906]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Sep 26 03:17:01 cloudkettle CRON[21041]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Sep 26 04:09:18 cloudkettle chronyd[534]: Source 132.226.17.96 replaced with 193.123.243.2 (2.ubuntu.pool.ntp.org)
Sep 26 04:17:01 cloudkettle CRON[21116]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Sep 26 04:44:52 cloudkettle snapd[1829]: storehelpers.go:748: cannot refresh: snap has no updates available: "amazon-ssm-agent", "core18", "core20", "lxd", "snapd"
Sep 26 04:44:52 cloudkettle snapd[1829]: autorefresh.go:540: auto-refresh: all snaps are up-to-date
Sep 26 05:17:01 cloudkettle CRON[21210]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Sep 26 05:20:30 cloudkettle systemd[1]: Starting Message of the Day...
Sep 26 05:20:32 cloudkettle 50-motd-news[21244]: * Ubuntu Pro delivers the most comprehensive open source security and
Sep 26 05:20:32 cloudkettle 50-motd-news[21244]: compliance features.
Sep 26 05:20:32 cloudkettle 50-motd-news[21244]: https://ubuntu.com/aws/pro
Sep 26 05:20:32 cloudkettle systemd[1]: motd-news.service: Deactivated successfully.
Sep 26 05:20:32 cloudkettle systemd[1]: Finished Message of the Day.
Sep 26 06:17:01 cloudkettle CRON[21316]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Sep 26 07:17:01 cloudkettle CRON[21396]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Sep 26 08:17:01 cloudkettle CRON[21466]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Sep 26 08:29:10 cloudkettle systemd[1]: Created slice User Slice of UID 1000.
Sep 26 08:29:10 cloudkettle systemd[1]: Starting User Runtime Directory /run/user/1000...
Sep 26 08:29:10 cloudkettle systemd[1]: Finished User Runtime Directory /run/user/1000.
Sep 26 08:29:10 cloudkettle systemd[1]: Starting User Manager for UID 1000...
Sep 26 08:29:10 cloudkettle systemd[21489]: Queued start job for default target Main User Target.
Sep 26 08:29:10 cloudkettle systemd[21489]: Created slice User Application Slice.
Sep 26 08:29:10 cloudkettle systemd[21489]: Reached target Paths.
Sep 26 08:29:10 cloudkettle systemd[21489]: Reached target Timers.
Sep 26 08:29:10 cloudkettle systemd[21489]: Starting D-Bus User Message Bus Socket...
Sep 26 08:29:10 cloudkettle systemd[21489]: Listening on GnuPG network certificate management daemon.
Sep 26 08:29:10 cloudkettle systemd[21489]: Listening on GnuPG cryptographic agent and passphrase cache (access for web browsers).
Sep 26 08:29:10 cloudkettle systemd[21489]: Listening on GnuPG cryptographic agent and passphrase cache (restricted).
Sep 26 08:29:10 cloudkettle systemd[21489]: Listening on GnuPG cryptographic agent (ssh-agent emulation).
Sep 26 08:29:10 cloudkettle systemd[21489]: Listening on GnuPG cryptographic agent and passphrase cache.
Sep 26 08:29:10 cloudkettle systemd[21489]: Listening on debconf communication socket.
Sep 26 08:29:10 cloudkettle systemd[21489]: Listening on REST API socket for snapd user session agent.
Sep 26 08:29:10 cloudkettle systemd[21489]: Listening on D-Bus User Message Bus Socket.
Sep 26 08:29:10 cloudkettle systemd[21489]: Reached target Sockets.
Sep 26 08:29:10 cloudkettle systemd[21489]: Reached target Basic System.
Sep 26 08:29:10 cloudkettle systemd[1]: Started User Manager for UID 1000.
Sep 26 08:29:10 cloudkettle systemd[1]: Started Session 100 of User ubuntu.
Sep 26 08:29:10 cloudkettle systemd[21489]: Reached target Main User Target.
Sep 26 08:29:10 cloudkettle systemd[21489]: Startup finished in 74ms.
Sep 26 08:29:10 cloudkettle systemd[1]: Started Session 102 of User ubuntu.
Sep 26 08:31:15 cloudkettle gunicorn[18272]: [2022-09-26 17:31:15 +0900] [18272] [INFO] Handling signal: term
Sep 26 08:31:15 cloudkettle gunicorn[18272]: Traceback (most recent call last):
Sep 26 08:31:15 cloudkettle gunicorn[18272]: File "/home/ubuntu/venvs/mysite/lib/python3.10/site-packages/gunicorn/arbiter.py", line 224, in run
Sep 26 08:31:15 cloudkettle systemd[1]: Stopping gunicorn daemon...
Sep 26 08:31:15 cloudkettle gunicorn[18274]: [2022-09-26 17:31:15 +0900] [18274] [INFO] Worker exiting (pid: 18274)
Sep 26 08:31:15 cloudkettle gunicorn[18275]: [2022-09-26 17:31:15 +0900] [18275] [INFO] Worker exiting (pid: 18275)
Sep 26 08:31:15 cloudkettle gunicorn[18272]: handler()
Sep 26 08:31:15 cloudkettle gunicorn[18272]: File "/home/ubuntu/venvs/mysite/lib/python3.10/site-packages/gunicorn/arbiter.py", line 257, in handle_term
Sep 26 08:31:15 cloudkettle gunicorn[18272]: raise StopIteration
Sep 26 08:31:15 cloudkettle gunicorn[18272]: StopIteration
Sep 26 08:31:15 cloudkettle gunicorn[18272]: During handling of the above exception, another exception occurred:
Sep 26 08:31:15 cloudkettle gunicorn[18272]: Traceback (most recent call last):
Sep 26 08:31:15 cloudkettle gunicorn[18272]: File "/home/ubuntu/venvs/mysite/bin/gunicorn", line 8, in <module>
Sep 26 08:31:15 cloudkettle gunicorn[18272]: sys.exit(run())
Sep 26 08:31:15 cloudkettle gunicorn[18272]: File "/home/ubuntu/venvs/mysite/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 67, in run
Sep 26 08:31:15 cloudkettle gunicorn[18272]: WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
Sep 26 08:31:15 cloudkettle gunicorn[18272]: File "/home/ubuntu/venvs/mysite/lib/python3.10/site-packages/gunicorn/app/base.py", line 231, in run
Sep 26 08:31:15 cloudkettle gunicorn[18272]: super().run()
Sep 26 08:31:15 cloudkettle gunicorn[18272]: File "/home/ubuntu/venvs/mysite/lib/python3.10/site-packages/gunicorn/app/base.py", line 72, in run
Sep 26 08:31:15 cloudkettle gunicorn[18272]: Arbiter(self).run()
Sep 26 08:31:15 cloudkettle gunicorn[18272]: File "/home/ubuntu/venvs/mysite/lib/python3.10/site-packages/gunicorn/arbiter.py", line 227, in run
Sep 26 08:31:15 cloudkettle gunicorn[18272]: self.halt()
Sep 26 08:31:15 cloudkettle gunicorn[18272]: File "/home/ubuntu/venvs/mysite/lib/python3.10/site-packages/gunicorn/arbiter.py", line 342, in halt
Sep 26 08:31:15 cloudkettle gunicorn[18272]: self.stop()
Sep 26 08:31:15 cloudkettle gunicorn[18272]: File "/home/ubuntu/venvs/mysite/lib/python3.10/site-packages/gunicorn/arbiter.py", line 382, in stop
Sep 26 08:31:15 cloudkettle gunicorn[18272]: sock.close_sockets(self.LISTENERS, unlink)
Sep 26 08:31:15 cloudkettle gunicorn[18272]: File "/home/ubuntu/venvs/mysite/lib/python3.10/site-packages/gunicorn/sock.py", line 212, in close_sockets
Sep 26 08:31:15 cloudkettle gunicorn[18272]: os.unlink(sock_name)
Sep 26 08:31:15 cloudkettle gunicorn[18272]: FileNotFoundError: [Errno 2] No such file or directory: '/tmp/gunicorn.sock'
Sep 26 08:31:15 cloudkettle systemd[1]: mysite.service: Main process exited, code=exited, status=1/FAILURE
Sep 26 08:31:15 cloudkettle systemd[1]: mysite.service: Failed with result 'exit-code'.
Sep 26 08:31:15 cloudkettle systemd[1]: Stopped gunicorn daemon.
Sep 26 08:31:15 cloudkettle systemd[1]: mysite.service: Consumed 14.070s CPU time.
Sep 26 08:31:15 cloudkettle systemd[1]: Started gunicorn daemon.
Sep 26 08:31:15 cloudkettle gunicorn[21679]: [2022-09-26 17:31:15 +0900] [21679] [INFO] Starting gunicorn 20.1.0
Sep 26 08:31:15 cloudkettle gunicorn[21679]: [2022-09-26 17:31:15 +0900] [21679] [INFO] Listening at: unix:/tmp/gunicorn.sock (21679)
Sep 26 08:31:15 cloudkettle gunicorn[21679]: [2022-09-26 17:31:15 +0900] [21679] [INFO] Using worker: sync
Sep 26 08:31:15 cloudkettle gunicorn[21681]: [2022-09-26 17:31:15 +0900] [21681] [INFO] Booting worker with pid: 21681
Sep 26 08:31:15 cloudkettle gunicorn[21682]: [2022-09-26 17:31:15 +0900] [21682] [INFO] Booting worker with pid: 21682
ekaqh8624 님 496
2022년 9월 26일 5:52 오후
1개의 답변이 있습니다. 1 / 1 Page
아고 질문을 잘못했네요. nginx도 설정했는데 정적파일을 못읽어서 구니콘 문제인줄 알았거든요.
-밑의 질문 한줄 요약 : /etc/nginx/nginx.conf에서 user를 nginx로 바꿔도 될까요?
nginx 설정 파일에 문제가 있나 했는데 확인해보니 멀쩡해서
(mysite) ubuntu@cloudkettle:~/projects/mysite$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
문제가 뭔지 알수 없어서 구글링해보니 에러 로그를 한 번 보라는 내용이 나왔습니다.
/var/log/nginx의 error.log를 보니 permission denied nginx 문제라서 또 구글링하니 소유권 문제라는걸 알게되었습니다.
/etc/nginx/nginx.conf를 /etc/nginx$ 에서 sudo nano nginx.conf 명령어로 아래와 같이 수정했습니다. 그러니 잘되더라고요! 3일간의 결실이 빛을 보네요!
(mysite) ubuntu@(유저이름):~/projects/mysite$ cd /etc/nginx
(mysite) ubuntu@(유저이름):/etc/nginx$ sudo nano nginx.conf
#본래는 user www-data;라고 되어있었습니다.
user nginx;
worker_processes auto;
pid /run/nginx.pid;
#...이하 생략
원래는 user root;로 하려고 했지만...nginx를 root권한이 있는 계정으로 사용자 등록하면 워커 프로세서를 악의적 사용자가 제어할 경우 문제가 될 수 있다고 댓글이 있어서 좀 불안하더라고요.
혹시 user nginx;도 무언가 문제가 생길수 있을까요?
M 2022년 9월 27일 2:54 오전