Configuring a Node.js Environment with Express and Vite: A Guide to Static File Management and Custom Routing - torarnehave1/slowyouio GitHub Wiki

Certainly! Below is an overview of the various files and configurations discussed in our previous conversations, including their purposes and how they interact within your system setup.

Files and Configurations Overview

1. Nginx Configuration Files

  • /etc/nginx/nginx.conf
    • The main configuration file for Nginx. It sets up the global settings and includes additional configuration files.
  • /etc/nginx/sites-available/default (or a specific site configuration file)
    • This file typically defines the server blocks for handling requests to different domains hosted on the server. It specifies how to handle HTTP and HTTPS requests, where to find website files, and how to proxy requests to backend services.

2. Proxy Parameters File

  • /etc/nginx/proxy_params
    • This included file contains common proxy header settings used by Nginx when proxying requests to a backend server. It helps pass essential information from the client through Nginx to the backend service.
    • Contents:
      • proxy_set_header Host $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;
      • proxy_http_version 1.1;
      • proxy_set_header Upgrade $http_upgrade;
      • proxy_set_header Connection "upgrade";

3. SSL Certificate Files

  • SSL certificate and key files used by Nginx for HTTPS:
    • /etc/letsencrypt/live/slowyou.io/fullchain.pem
    • /etc/letsencrypt/live/slowyou.io/privkey.pem
    • These files are generated by Let's Encrypt and are used to secure communications to and from the server.

4. Node.js Application Files

  • main.js
    • The primary server script for your Node.js application, typically running an Express server. It handles backend logic and API responses.
  • package.json
    • Defines project metadata, scripts, and dependencies for a Node.js project. It's used to manage project packages with npm.

5. Cron Job Script

  • Cron configuration in /etc/cron.d
    • A script or job entry that regularly updates the server's content by pulling the latest changes from a GitHub repository to the local directory. This setup automates deployment and keeps the server up-to-date with the latest code changes.
    • Typically runs a command like: */5 * * * * cd /var/www/html/slowyouio && git pull

6. Static and Dynamic Content Handling

  • Static files path:
    • /var/www/html/slowyouio/public
    • Contains static resources like CSS, JavaScript, and images, which are served directly by Nginx.
  • Dynamic content handled by Node.js:
    • Proxied through Nginx, typically from requests to paths not directly corresponding to static files.

7. Vite Development Environment

  • vite.config.js
    • Configuration file for Vite, a frontend build tool, which enhances the development experience with features like hot module replacement (HMR). It can also include proxy settings for development, routing API calls to the Node.js backend.

8. Web Server and Application Directories

  • Web Root Directory:
    • /var/www/html/slowyouio
    • The root directory where your Node.js application and static files are located, used by Nginx as the base path for serving files and handling requests.

Summary

This overview encapsulates the main components of your web server setup, involving Nginx for web serving and reverse proxy tasks, Let's Encrypt for SSL/TLS security, Node.js for backend services, Vite for frontend development, and automation scripts for continuous deployment. Each component plays a role in ensuring that your web application is secure, efficient, and up-to-date.