写入 /var/www/ 文件夹的权限被拒绝
permission denied to write into /var/www/ folder
我的 python 应用程序正在使用 sentence_transformers
包,它试图写入我的 ubuntu 系统上的 /var/www/
目录。
这是当前显示的错误:
Thu Aug 19 18:33:32.980245 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] mod_wsgi (pid=50371): Failed to exec Python script file '/var/www/html/flaskapp/production.wsgi'.
[Thu Aug 19 18:33:32.980302 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] mod_wsgi (pid=50371): Exception occurred processing WSGI script '/var/www/html/flaskapp/production.wsgi'.
[Thu Aug 19 18:33:32.980465 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] Traceback (most recent call last):
[Thu Aug 19 18:33:32.980514 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/var/www/html/flaskapp/production.wsgi", line 7, in <module>
[Thu Aug 19 18:33:32.980520 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] from run_app import app as application
[Thu Aug 19 18:33:32.980531 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/var/www/html/flaskapp/run_app.py", line 4, in <module>
[Thu Aug 19 18:33:32.980536 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] import utils as helper
[Thu Aug 19 18:33:32.980546 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/var/www/html/flaskapp/utils.py", line 5, in <module>
[Thu Aug 19 18:33:32.980551 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] model = SentenceTransformer('stsb-roberta-large')
[Thu Aug 19 18:33:32.980561 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/var/www/html/flaskapp/venv/lib/python3.8/site-packages/sentence_transformers/SentenceTransformer.py", line 81, in __init__
[Thu Aug 19 18:33:32.980566 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] model_path_tmp = snapshot_download(model_name_or_path,
[Thu Aug 19 18:33:32.980577 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/var/www/html/flaskapp/venv/lib/python3.8/site-packages/sentence_transformers/util.py", line 424, in snapshot_download
[Thu Aug 19 18:33:32.980582 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] os.makedirs(nested_dirname, exist_ok=True)
[Thu Aug 19 18:33:32.980592 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/usr/lib/python3.8/os.py", line 213, in makedirs
[Thu Aug 19 18:33:32.980597 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] makedirs(head, exist_ok=exist_ok)
[Thu Aug 19 18:33:32.980607 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/usr/lib/python3.8/os.py", line 213, in makedirs
[Thu Aug 19 18:33:32.980611 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] makedirs(head, exist_ok=exist_ok)
[Thu Aug 19 18:33:32.980621 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/usr/lib/python3.8/os.py", line 213, in makedirs
[Thu Aug 19 18:33:32.980625 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] makedirs(head, exist_ok=exist_ok)
[Thu Aug 19 18:33:32.980635 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/usr/lib/python3.8/os.py", line 223, in makedirs
[Thu Aug 19 18:33:32.980640 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] mkdir(name, mode)
[Thu Aug 19 18:33:32.980640 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] PermissionError: [Errno 13] Permission denied: '/var/www/.cache'
/var/www
目录的权限设置:
ubuntu@ip-xxx-xx-xx-xxx:/var$ ls -l
total 48
drwxr-xr-x 3 root root 4096 Aug 18 19:38 www
drwxr-xr-x 2 root root 4096 Aug 19 13:24 backups
drwxr-xr-x 14 root root 4096 Aug 19 11:03 cache
drwxrwxrwt 2 root root 4096 Apr 30 23:25 crash
drwxr-xr-x 39 root root 4096 Aug 18 19:38 lib
drwxrwsr-x 2 root staff 4096 Apr 15 2020 local
lrwxrwxrwx 1 root root 9 Apr 30 23:15 lock -> /run/lock
drwxrwxr-x 10 root syslog 4096 Aug 18 19:38 log
drwxrwsr-x 2 root mail 4096 Apr 30 23:15 mail
drwxr-xr-x 2 root root 4096 Apr 30 23:15 opt
lrwxrwxrwx 1 root root 4 Apr 30 23:15 run -> /run
drwxr-xr-x 6 root root 4096 Apr 30 23:36 snap
drwxr-xr-x 4 root root 4096 Apr 30 23:17 spool
drwxrwxrwt 7 root root 4096 Aug 19 18:11 tmp
为/var/www/
设置chmod 777
是否理想?
不要那样做 (777)。
细化(见上面的评论)。
touch /var/www/.cache
chgrp www-data /var/www/.cache
chmod g+w /var/www/.cache
我的 python 应用程序正在使用 sentence_transformers
包,它试图写入我的 ubuntu 系统上的 /var/www/
目录。
这是当前显示的错误:
Thu Aug 19 18:33:32.980245 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] mod_wsgi (pid=50371): Failed to exec Python script file '/var/www/html/flaskapp/production.wsgi'.
[Thu Aug 19 18:33:32.980302 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] mod_wsgi (pid=50371): Exception occurred processing WSGI script '/var/www/html/flaskapp/production.wsgi'.
[Thu Aug 19 18:33:32.980465 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] Traceback (most recent call last):
[Thu Aug 19 18:33:32.980514 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/var/www/html/flaskapp/production.wsgi", line 7, in <module>
[Thu Aug 19 18:33:32.980520 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] from run_app import app as application
[Thu Aug 19 18:33:32.980531 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/var/www/html/flaskapp/run_app.py", line 4, in <module>
[Thu Aug 19 18:33:32.980536 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] import utils as helper
[Thu Aug 19 18:33:32.980546 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/var/www/html/flaskapp/utils.py", line 5, in <module>
[Thu Aug 19 18:33:32.980551 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] model = SentenceTransformer('stsb-roberta-large')
[Thu Aug 19 18:33:32.980561 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/var/www/html/flaskapp/venv/lib/python3.8/site-packages/sentence_transformers/SentenceTransformer.py", line 81, in __init__
[Thu Aug 19 18:33:32.980566 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] model_path_tmp = snapshot_download(model_name_or_path,
[Thu Aug 19 18:33:32.980577 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/var/www/html/flaskapp/venv/lib/python3.8/site-packages/sentence_transformers/util.py", line 424, in snapshot_download
[Thu Aug 19 18:33:32.980582 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] os.makedirs(nested_dirname, exist_ok=True)
[Thu Aug 19 18:33:32.980592 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/usr/lib/python3.8/os.py", line 213, in makedirs
[Thu Aug 19 18:33:32.980597 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] makedirs(head, exist_ok=exist_ok)
[Thu Aug 19 18:33:32.980607 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/usr/lib/python3.8/os.py", line 213, in makedirs
[Thu Aug 19 18:33:32.980611 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] makedirs(head, exist_ok=exist_ok)
[Thu Aug 19 18:33:32.980621 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/usr/lib/python3.8/os.py", line 213, in makedirs
[Thu Aug 19 18:33:32.980625 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] makedirs(head, exist_ok=exist_ok)
[Thu Aug 19 18:33:32.980635 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] File "/usr/lib/python3.8/os.py", line 223, in makedirs
[Thu Aug 19 18:33:32.980640 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] mkdir(name, mode)
[Thu Aug 19 18:33:32.980640 2021] [wsgi:error] [pid 50371:tid 140121496090368] [client 95.138.162.70:43396] PermissionError: [Errno 13] Permission denied: '/var/www/.cache'
/var/www
目录的权限设置:
ubuntu@ip-xxx-xx-xx-xxx:/var$ ls -l
total 48
drwxr-xr-x 3 root root 4096 Aug 18 19:38 www
drwxr-xr-x 2 root root 4096 Aug 19 13:24 backups
drwxr-xr-x 14 root root 4096 Aug 19 11:03 cache
drwxrwxrwt 2 root root 4096 Apr 30 23:25 crash
drwxr-xr-x 39 root root 4096 Aug 18 19:38 lib
drwxrwsr-x 2 root staff 4096 Apr 15 2020 local
lrwxrwxrwx 1 root root 9 Apr 30 23:15 lock -> /run/lock
drwxrwxr-x 10 root syslog 4096 Aug 18 19:38 log
drwxrwsr-x 2 root mail 4096 Apr 30 23:15 mail
drwxr-xr-x 2 root root 4096 Apr 30 23:15 opt
lrwxrwxrwx 1 root root 4 Apr 30 23:15 run -> /run
drwxr-xr-x 6 root root 4096 Apr 30 23:36 snap
drwxr-xr-x 4 root root 4096 Apr 30 23:17 spool
drwxrwxrwt 7 root root 4096 Aug 19 18:11 tmp
为/var/www/
设置chmod 777
是否理想?
不要那样做 (777)。
细化(见上面的评论)。
touch /var/www/.cache
chgrp www-data /var/www/.cache
chmod g+w /var/www/.cache