Skip to main content

nginxsitepy

A command-line tool for managing Nginx site configurations with location-based operations.

Features

  • Easy Location Management: Add, delete, and modify Nginx location blocks
  • Directive Management: Add directives to specific locations while preserving order
  • State Persistence: Remember configuration file settings between commands
  • Clean Formatting: Maintain proper indentation and avoid unnecessary blank lines
  • Safe Operations: Backup and validate configurations before changes

Installation

pip install nginxsitepy

Quick Start

  1. Set your Nginx configuration file:
nginx-sites set_config /etc/nginx/sites-enabled/default
  1. Add a location block:
nginx-sites add /api
  1. Add directives to a location:
nginx-sites directive /api "proxy_pass http://localhost:3000"
nginx-sites directive /api "proxy_set_header Host \$host"
  1. View your configuration:
nginx-sites summary

Commands

Configuration Management

  • nginx-sites set_config <file> - Set the Nginx configuration file to work with
  • nginx-sites status - Show current configuration status
  • nginx-sites clear - Clear saved state

Location Operations

  • nginx-sites list - List all location blocks
  • nginx-sites show <path> - Show details of a specific location
  • nginx-sites add <path> [directive] - Add a new location block (optionally with a directive)
  • nginx-sites delete <path> - Delete a location block

Directive Management

  • nginx-sites directive <path> <directive> - Add a directive to a location block

Information

  • nginx-sites summary - Show a complete summary of all locations and directives

Examples

Basic Flask Application Setup

# Set configuration file
nginx-sites set_config /etc/nginx/sites-enabled/default

# Add main location
nginx-sites add /
nginx-sites directive / "try_files \$uri @flask_application"

# Add Flask upstream location
nginx-sites add @flask_application
nginx-sites directive @flask_application "proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for"
nginx-sites directive @flask_application "proxy_set_header X-Forwarded-Proto \$scheme"
nginx-sites directive @flask_application "proxy_set_header Host \$http_host"
nginx-sites directive @flask_application "proxy_redirect off"
nginx-sites directive @flask_application "proxy_pass http://localhost:8000"

API Gateway Setup

# API endpoints
nginx-sites add /api/v1
nginx-sites directive /api/v1 "proxy_pass http://api-server:3000"

nginx-sites add /api/v2
nginx-sites directive /api/v2 "proxy_pass http://api-server-v2:3001"

# Static files
nginx-sites add /static
nginx-sites directive /static "root /var/www"
nginx-sites directive /static "expires 30d"

View Configuration

# List all locations
nginx-sites list

# Show specific location
nginx-sites show /api/v1

# Complete summary
nginx-sites summary

Options

  • --server, -s INDEX - Specify server block index (default: 0)

Example:

nginx-sites --server 1 list
nginx-sites -s 1 directive / "root /var/www/site2"

Requirements

  • Python 3.9+
  • Read/write access to Nginx configuration files

Development

Clone the repository:

git clone <repository-url>
cd nginxsitepy

Install in development mode:

pip install -e .

License

MIT License

Author

ji-ho lee (search5@gmail.com)

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

Changelog

0.1.0

  • Initial release
  • Basic location and directive management
  • State persistence
  • Clean formatting and indentation preservation

Release files for nginxsitepy 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nginxsitepy 0.1.0
File Size Uploaded
nginxsitepy-0.1.0.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nginxsitepy 0.1.0
File Interpreter ABI Platform
nginxsitepy-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.6 kB

Release files / nginxsitepy-0.1.0.tar.gz

Download URL nginxsitepy-0.1.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5b09e40fcb23b5934977aadb3dba45cfc9f86588c480337f724036b1465f765e
BLAKE2b-256 checksum
How to use checksums
43e51e1866453afe2af638026f24a6ecbe479f1b88996313fb4e33a82ebe187f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.10.12 Linux/6.8.0-60-generic

Release files / nginxsitepy-0.1.0-py3-none-any.whl

Download URL nginxsitepy-0.1.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b604053a8ea9192575b8cf93b6073ce38c348abb92cb1bf87b786332c44496e
BLAKE2b-256 checksum
How to use checksums
9aceb639bbd7b1257570b419a3036399ed1481e1d263e52b6c97b79b690eafd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.10.12 Linux/6.8.0-60-generic

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page