Skip to content

Instantly share code, notes, and snippets.

@azer
Created October 27, 2024 07:15
Show Gist options
  • Save azer/f890cb61abd60ee910f14240ed8081fc to your computer and use it in GitHub Desktop.
Save azer/f890cb61abd60ee910f14240ed8081fc to your computer and use it in GitHub Desktop.
nginx_help.md

Ubuntu Server Management Guide

Website Management System

This guide explains how to manage websites on your Ubuntu server using the custom management system.

Directory Structure

~/dev/
├── help.md           # This help file
└── www/             # Web root directory
    ├── default/     # Default website
    ├── manage.sh    # Management script
    └── example.com/ # Domain-specific website

Quick Start

  1. Create a new website:
~/dev/www/manage.sh create mydomain.com
  1. Remove a website:
~/dev/www/manage.sh remove mydomain.com
  1. List all websites:
~/dev/www/manage.sh list

Detailed Usage

Creating a New Website

When you create a new website:

  • A new directory is created at ~/dev/www/mydomain.com
  • Nginx configuration is set up automatically
  • A default index.html is created
  • The site is enabled and Nginx is reloaded

Removing a Website

When removing a website:

  • The Nginx configuration is removed
  • The website files remain intact
  • Nginx is reloaded automatically

File Locations

  • Website Content: ~/dev/www/<domain>/
  • Nginx Configs: /etc/nginx/sites-available/
  • Active Configs: /etc/nginx/sites-enabled/

Common Tasks

Editing Website Content

# Edit main page
nano ~/dev/www/mydomain.com/index.html

# Add new files
cp myfile.html ~/dev/www/mydomain.com/

Managing Nginx

# Test configuration
sudo nginx -t

# Reload configuration
sudo systemctl reload nginx

# Restart Nginx
sudo systemctl restart nginx

# Check status
sudo systemctl status nginx

Viewing Logs

# Access log
sudo tail -f /var/log/nginx/access.log

# Error log
sudo tail -f /var/log/nginx/error.log

Best Practices

  1. Always test Nginx configuration after changes:
sudo nginx -t
  1. Use relative paths in your HTML:
<img src="/images/logo.png">  <!-- Good -->
<img src="images/logo.png">   <!-- Might break -->
  1. Set proper permissions:
chmod -R 755 ~/dev/www/<domain>
  1. Backup before major changes:
cp -r ~/dev/www/<domain> ~/dev/www/<domain>.backup

Troubleshooting

  1. If Nginx fails to start:

    • Check error logs: sudo tail -f /var/log/nginx/error.log
    • Verify config: sudo nginx -t
    • Check permissions: ls -la ~/dev/www/
  2. If website is not accessible:

    • Verify domain DNS points to your server
    • Check Nginx config exists in sites-enabled
    • Ensure no firewall blocking port 80/443
  3. If changes don't appear:

    • Clear browser cache
    • Verify file permissions
    • Check Nginx worker processes

Getting Help

  • View this guide: cat ~/dev/help.md
  • View script help: ~/dev/www/manage.sh help
  • Check Nginx docs: https://nginx.org/en/docs/
  • Check logs: sudo tail -f /var/log/nginx/error.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment