You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS Ubuntu Server 16.04部署Django作品集遇内部服务器错误求助

Troubleshooting Internal Server Error for Django Portfolio on AWS Ubuntu 16.04

Hey there, let's dig into that frustrating Internal Server Error you're hitting with your Django portfolio deployment. I’ll walk you through targeted checks and fixes based on the steps you’ve already shared.

1. First, Check the Logs (Most Critical!)

When DEBUG = False in production, Django hides detailed error messages—so server logs are your best bet to find the root cause:

  • Check Gunicorn logs (reveals issues with your Django app itself):
    sudo journalctl -u gunicorn -f
    
    The -f flag lets you watch logs in real time. Try accessing your site while this runs, and you’ll likely see specific errors (like missing dependencies, database misconfigs, or incorrect file paths).
  • Check Nginx error logs (for communication issues between Nginx and Gunicorn):
    sudo tail -f /var/log/nginx/error.log
    
    Common issues here include missing socket files or permission conflicts between services.

2. Verify File & Directory Permissions

Permissions are one of the most frequent culprits for 500 errors:

  • Ensure your project directory is accessible by both the ubuntu user and www-data group (as specified in your Gunicorn config):
    sudo chown -R ubuntu:www-data /home/ubuntu/portfolio
    
  • Give read access to your static files directory:
    sudo chmod -R 755 /home/ubuntu/portfolio/static
    
  • Check if the Gunicorn socket file exists and has correct permissions:
    ls -l /home/ubuntu/portfolio/portfolio.sock
    
    If the socket doesn’t exist, Gunicorn failed to start—go back to the Gunicorn logs to diagnose why. If it does exist, confirm it’s owned by ubuntu:www-data with permissions like srw-rw---- (660) so Nginx can interact with it.

3. Validate Django Configuration

Double-check your settings.py for easy-to-miss mistakes:

  • ALLOWED_HOSTS: While ['52.14.89.55'] is correct, you can temporarily set it to ['*'] to rule out host-related issues (don’t leave this in production!).
  • STATIC_ROOT: Confirm the path is accurate by running:
    cd /home/ubuntu/portfolio && python -c "import os; print(os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), 'static/'))"
    
    This should match your STATIC_ROOT value. Also, verify collectstatic populated the static directory:
    ls /home/ubuntu/portfolio/static
    
    If it’s empty, re-run python manage.py collectstatic and check for errors during execution.
  • Database Setup: If using a database (like SQLite), ensure the database file exists and has read/write permissions for the ubuntu user.

4. Test Gunicorn Manually

Bypass Nginx entirely to confirm your Django app can run with Gunicorn:

  1. Activate your virtual environment:
    source /home/ubuntu/portfolio/venv/bin/activate
    
  2. Start Gunicorn directly on a port:
    gunicorn --bind 0.0.0.0:8000 portfolio.wsgi:application
    
  3. Try accessing http://52.14.89.55:8000 in your browser. If this fails, you’ll see detailed Django errors (since you’re running it directly) that will point you to the exact problem (e.g., missing packages, syntax errors in settings.py).

5. Check Nginx Configuration Details

Even though nginx -t passed, there might be subtle issues:

  • Verify the proxy_params file exists (it should be default on Ubuntu 16.04):
    ls /etc/nginx/proxy_params
    
    If it’s missing, create it with these contents:
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    
  • Ensure your Nginx site configuration doesn’t conflict with the default site. Confirm the default is removed:
    sudo rm /etc/nginx/sites-enabled/default
    
    Then restart Nginx again:
    sudo service nginx restart
    

6. Ubuntu 16.04 Specific Checks

  • Confirm your virtual environment is using Python 3 (since you specified --python=python3):
    source /home/ubuntu/portfolio/venv/bin/activate && pip --version
    
    The output should show a Python 3.x version (Ubuntu 16.04’s default is 3.5). If not, recreate your virtual environment with virtualenv venv --python=python3.5.

Start with the log checks—they’ll almost always tell you exactly what’s broken. Once you resolve that issue, your portfolio should load up smoothly!

内容的提问来源于stack exchange,提问作者Andy Nguyen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 08:25:13