No project description provided
Project description
nginx-python
Overview
nginx-python is a Python package designed to automatically and easily configure and host your Python web applications (Django, Flask, FastAPI) with Nginx using simple Python code. This tool aims to streamline the deployment process, reducing the complexity and potential for errors associated with manual configuration.
Features
- Automatic Nginx Configuration: Generate Nginx configuration files tailored to your application’s needs with minimal effort.
- Service Management: Start, stop, and reload Nginx services directly from your Python code.
- SSL Certificate Integration: Optionally integrate Let's Encrypt SSL certificates to secure your applications.
- Multi-Framework Support: Seamlessly supports Django, Flask, and FastAPI web frameworks.
- User-Friendly: Simplifies the deployment process, making it accessible even to developers who are not familiar with server configuration.
Installation
Install Python-nginx via pip:
pip install nginx-python
Usage
Basic Setup
Here’s a quick example of how to set up Nginx for a FastAPI application:
from nginx_python.core import create_nginx_config, manage_service
# Define your server name and application port
server_name = 'example.com'
app_port = 8000
# Generate the Nginx configuration
create_nginx_config(server_name, app_port)
# Start the Nginx service
manage_service('start')
Set up SSL certificate configuration path
from nginx_python.core import create_nginx_config, manage_service
# Define your Nginx conf setup
server_name = 'example.com'
app_name = 'django'
app_port = 8000
use_ssl = True
ssl_certificate_path='your_certificate_path'
ssl_certificate_key_path = 'your_certificate_key_path'
# Generate the Nginx configuration
create_nginx_config(server_name=server_name, app_port=app_port,
app_name=app_name, use_ssl=use_ssl,
ssl_certificate_path=ssl_certificate_path,
ssl_certificate_key_path=ssl_certificate_key_path)
# Start the Nginx service
manage_service('start')
Command-Line Interface
Python-nginx also provides a CLI for easy management:
nginx_python setup --server-name example.com --app-port 8000
nginx_python start
nginx_python stop
nginx_python reload
Configuration File Template
The default Nginx configuration template used by Python-nginx:
server {
listen 80;
server_name {{ server_name }};
location / {
proxy_pass http://{{ app_name }}:{{ app_port }};
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;
}
error_page 404 /404.html;
location = /404.html {
internal;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
internal;
}
}
Contributing
Contributions are welcome! Please read our contributing guide to get started.
License
This project is licensed under the MIT License. See the LICENSE file for more details.
GitHub Actions Workflow
This repository includes a GitHub Actions workflow to automatically test and publish the package to PyPI. For more information, see the workflow file.
Contact
For any questions or feedback, please contact barseghyangor8@gmail.com.
With nginx-python, deploying your Python web applications has never been easier. Simplify your server configuration and focus on building great applications!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file nginx_python-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: nginx_python-0.1.2-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c706fbba8a67640f13b93c84f10102df21c0a310a3faaa51cb27d36746d7e7de |
|
MD5 | 5b025274248da5d3ba0ad2c847d6903c |
|
BLAKE2b-256 | d93c78a7f6215a3bf481aaca7b81d041d16475f71716df246bdbe306e775685c |