Apache 錯誤:將 python 日誌寫入專案目錄以外的檔案時

Apache 錯誤:將 python 日誌寫入專案目錄以外的檔案時

我正在開發 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

相關內容