![Apache 錯誤:將 python 日誌寫入專案目錄以外的檔案時](https://rvso.com/image/726400/Apache%20%E9%8C%AF%E8%AA%A4%EF%BC%9A%E5%B0%87%20python%20%E6%97%A5%E8%AA%8C%E5%AF%AB%E5%85%A5%E5%B0%88%E6%A1%88%E7%9B%AE%E9%8C%84%E4%BB%A5%E5%A4%96%E7%9A%84%E6%AA%94%E6%A1%88%E6%99%82.png)
我正在開發 Django 專案並使用 Apache 作為 Web 伺服器。一切工作正常
python manage.py runserver
但是,當透過 apache 運行應用程式時,我無法將 python 應用程式日誌寫入專案目錄之外的指定路徑。
專案目錄/home/ubuntu/saas-DocumentProcessing
日誌檔案位於
/home/ubuntu/log/SaasAap/SaasAap.log
和/home/ubuntu/log/error/error.log
我的000-default.conf
內容
<VirtualHost *:8000>
ServerAdmin [email protected]
ServerName my_ip
ServerAlias my_ip
DocumentRoot /home/ubuntu/saas-DocumentProcessing/
WSGIScriptAlias / /home/ubuntu/saas-DocumentProcessing/src/wsgi.py
Alias /static/ /home/ubuntu/saas-DocumentProcessing/static/
ErrorLog /home/ubuntu/log/error.log
CustomLog /home/ubuntu/log/custom.log combined
<Location "/static/">
Options -Indexes
AllowOverride All
Require all granted
</Location>
<Location "/">
AllowOverride All
Require all granted
</Location>
<Directory /home/ubuntu/saas-DocumentProcessing/static>
Order allow,deny
Allow from all
</Directory>
<Directory /home/ubuntu/log>
Order allow,deny
Allow from all
</Directory>
WSGIDaemonProcess saas-DocumentProcessing python-path=/home/ubuntu/
saas-DocumentProcessing python-home=/home/ubuntu/saas-DocumentProcessing/ve
nv
WSGIProcessGroup saas-DocumentProcessing
</VirtualHost>
答案1
步驟 1:找出 Apache 正在以什麼使用者身分執行:
ps aux | egrep '(apache|httpd)'
然後檢查您將日誌寫入到的目錄的檔案擁有權和權限。變更此目錄(及其子目錄)的擁有者以符合 Apache,或變更檔案權限以允許寫入此目錄。
最好的解決方案是更改所有者:
sudo chown -R <user_from_above> /home/ubuntu/log
一種不安全的方法是更改權限:
sudo chmod 777 /home/ubuntu/log
sudo chmod 777 /home/ubuntu/log/SaasAap