Welcome to Your Django VPS Environment

Congratulations! Your server has been successfully provisioned. We have pre-configured a robust stack for you, including Nginx (Web Server), Gunicorn (WSGI Application Server), and Django (Framework).

How the Architecture Works

To help you understand how your application runs, here is the flow of your traffic:

  1. Nginx receives the web request.

  2. It serves static files (CSS, JS, Images) directly for speed.

  3. It passes dynamic requests to Gunicorn.

  4. Gunicorn communicates with your Django application.


1. Verification: Is Django Working?

If you have visited your server's IP address in a web browser and see the "Rocket" success page, your environment is correctly installed.

ohogiubg

If you are logged into your server via SSH and want to double-check the installation, run:

Bash
 
python3 -c "import django; print(f'Django Version: {django.get_version()}')"

2. File Location & Access

Your project files are located in: /var/www/marketplace/

Important: Your application runs under the www-data user for security. When running Django management commands (like migrations), always use sudo -u www-data.


3. Essential Management Commands

Whenever you update your code or change your Django configuration, you will need to restart the services.

A. Managing the Django Application

Navigate to your project folder first:

Bash
 
cd /var/www/marketplace

Apply database changes (Migrations):

Bash
 
sudo -u www-data python3 manage.py migrate

Collect static files (If you added CSS/JS):

Bash
 
sudo -u www-data python3 manage.py collectstatic --noinput

B. Restarting Services

If your changes are not appearing on the website, restart the services in this order:

Restart the Gunicorn server (to load new Python code):

Bash
 
sudo systemctl restart gunicorn

Restart Nginx (to load new configuration changes):

Bash
 
sudo systemctl restart nginx

4. Deployment Checklist

When you are ready to deploy your own code to this VPS, follow this workflow:

  1. Upload/Pull Code: Move your files into /var/www/marketplace/ (replacing the default Django files).

  2. Install Requirements: If you have a requirements.txt, install them via:

    sudo -u www-data pip3 install -r requirements.txt

  3. Run Migrations: Execute sudo -u www-data python3 manage.py migrate.

  4. Collect Static: Execute sudo -u www-data python3 manage.py collectstatic.

  5. Restart Services: Run sudo systemctl restart gunicorn to apply the changes.


 Pro-Tips for Production

  • Settings File: Ensure your settings.py is configured for production. You should set DEBUG = False and update ALLOWED_HOSTS to include your actual domain name/IP address.

  • Log Files: If your site isn't loading, check the Nginx error logs:

    tail -f /var/log/nginx/error.log

Hjalp dette svar dig? 0 Kunder som kunne bruge dette svar (0 Stem)