NGINX & UWSGI启动服务器时出现权限拒绝问题
Hey there, let's tackle that permission error you're hitting when trying to start uWSGI. The root issue here is that your pi user doesn't have write access to the /var/log/uwsgi directory or the specific log file. Here's how to fix it step by step:
Step 1: Verify the log directory's permissions
First, check who owns the /var/log/uwsgi directory and what permissions it has. Run this command:
ls -ld /var/log/uwsgi
This will show you the owner (like root:root) and permission settings (like drwxr-xr-x). If the pi user isn't the owner or doesn't have write permissions, that's the core problem.
Step 2: Create the log directory (if it doesn't exist)
If the /var/log/uwsgi directory doesn't exist at all, create it first with sudo:
sudo mkdir -p /var/log/uwsgi
Step 3: Adjust permissions to let your user write to the directory
You have two main options here, depending on how you plan to run uWSGI:
Option A: Give the pi user ownership
If you're running uWSGI as the pi user (which you are, since you're in your virtual environment), set the directory owner to pi:
sudo chown pi:pi /var/log/uwsgi # Then set proper directory permissions to ensure access sudo chmod 755 /var/log/uwsgi
Option B: Use the web server user (for production)
If you're setting this up for production and will run uWSGI as the www-data user (common for Nginx/Apache setups), set ownership to that user instead:
sudo chown www-data:www-data /var/log/uwsgi sudo chmod 755 /var/log/uwsgi
Step 4: Test the uWSGI command again
Once permissions are set, go back to your virtual environment and run the original command again:
uwsgi --ini /var/www/lab_app/lab_app_uwsgi.ini
Quick alternative (not recommended for production)
If you just need to test quickly, you can run uWSGI with sudo to bypass permissions temporarily:
sudo uwsgi --ini /var/www/lab_app/lab_app_uwsgi.ini
Note: Running uWSGI as root carries security risks, so only use this for testing and stick to the permission adjustment method for production setups.
Final check
Double-check your lab_app_uwsgi.ini file to make sure the log path is spelled correctly. The relevant line should look something like:
logto = /var/log/uwsgi/lab_app_uwsgi.log
内容的提问来源于stack exchange,提问作者S.Q

