All Projects → peakwinter → Python Nginx

peakwinter / Python Nginx

Licence: gpl-3.0
Create and modify nginx serverblock configs in Python

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Labels

Projects that are alternatives of or similar to Python Nginx

Blog
MyBlog
Stars: ✭ 197 (-12.83%)
Mutual labels:  nginx
Kickoff Docker Php
🐳 🐘 🚀 Easily setup a PHP project with Docker
Stars: ✭ 213 (-5.75%)
Mutual labels:  nginx
Nginx Boilerplate
Awesome Nginx configuration template
Stars: ✭ 2,437 (+978.32%)
Mutual labels:  nginx
Ansible Rails
Ruby on Rails deployment using Ansible - with Lets Encrypt, Sidekiq, PostgreSQL, nginx & puma
Stars: ✭ 199 (-11.95%)
Mutual labels:  nginx
Blog
Hi, I am CrazyCodes, and here are all my articles
Stars: ✭ 212 (-6.19%)
Mutual labels:  nginx
Uwsgi Nginx Flask Docker
Docker image with uWSGI and Nginx for Flask applications in Python running in a single container. Optionally with Alpine Linux.
Stars: ✭ 2,607 (+1053.54%)
Mutual labels:  nginx
Nginx Sso
SSO authentication provider for the auth_request nginx module
Stars: ✭ 195 (-13.72%)
Mutual labels:  nginx
Nginx Config Formatter
nginx config file formatter/beautifier written in Python.
Stars: ✭ 222 (-1.77%)
Mutual labels:  nginx
Ipscrub
IP address anonymizer module for nginx
Stars: ✭ 212 (-6.19%)
Mutual labels:  nginx
Lnmp
LEMP stack/LAMP stack/LNMP stack installation scripts for CentOS/Redhat Debian and Ubuntu
Stars: ✭ 2,488 (+1000.88%)
Mutual labels:  nginx
Net Shield
An Easy and Simple Anti-DDoS solution for VPS,Dedicated Servers and IoT devices - Beta
Stars: ✭ 202 (-10.62%)
Mutual labels:  nginx
Nginx Module Vts
Nginx virtual host traffic status module
Stars: ✭ 2,518 (+1014.16%)
Mutual labels:  nginx
Django2 dailyfresh
dailyfresh电商项目,替换django框架为2.X并重构,美化了下后台管理页面,提供docker版本,该项目包含了实际开发中的电商项目中大部分的功能开发和知识点实践, 是一个非常不错的django学习项目,同时也记录在替换框架中遇到的坑,希望对各位的学习有所帮助。
Stars: ✭ 212 (-6.19%)
Mutual labels:  nginx
Bitnami Docker Nginx
Bitnami nginx Docker Image
Stars: ✭ 198 (-12.39%)
Mutual labels:  nginx
Opensa
资产管理、资产采集、灰度发布、反向代理、批量任务、任务编排、计划任务、日志审计、权限管理、角色管理、部门管理、运维自动化
Stars: ✭ 220 (-2.65%)
Mutual labels:  nginx
Nginx Link Function
It is a NGINX module that provides dynamic linking to your application in server context and call the function of your application in location directive
Stars: ✭ 197 (-12.83%)
Mutual labels:  nginx
Bubbly
Better SSL in Nginx in 10 minutes. Configuration files and setup scripts for Certbot.
Stars: ✭ 213 (-5.75%)
Mutual labels:  nginx
Nginx Rtmp Monitoring
real-time monitoring statistics dashboard for nginx rtmp module
Stars: ✭ 224 (-0.88%)
Mutual labels:  nginx
Traffic Accounting Nginx Module
Monitor the incoming and outgoing traffic metrics in realtime for NGINX
Stars: ✭ 222 (-1.77%)
Mutual labels:  nginx
Jinx
✨jinx - a magical nginx wrapper
Stars: ✭ 215 (-4.87%)
Mutual labels:  nginx

python-nginx

A module for easily creating and modifying nginx serverblock configurations in Python (including comments!).

Install

pip install python-nginx

Examples

Create an nginx serverblock and save it to file:

>>> import nginx
>>> c = nginx.Conf()
>>> u = nginx.Upstream('php',
...     nginx.Key('server', 'unix:/tmp/php-fcgi.socket')
...	)
>>> c.add(u)
>>> s = nginx.Server()
>>> s.add(
...     nginx.Key('listen', '80'),
...     nginx.Comment('Yes, python-nginx can read/write comments!'),
...     nginx.Key('server_name', 'localhost 127.0.0.1'),
...     nginx.Key('root', '/srv/http'),
...     nginx.Key('index', 'index.php'),
...     nginx.Location('= /robots.txt',
...          nginx.Key('allow', 'all'),
...          nginx.Key('log_not_found', 'off'),
...          nginx.Key('access_log', 'off')
...     ),
...     nginx.Location('~ \.php$',
...          nginx.Key('include', 'fastcgi.conf'),
...          nginx.Key('fastcgi_intercept_errors', 'on'),
...          nginx.Key('fastcgi_pass', 'php')
...     )
... )
>>> c.add(s)
>>> nginx.dumpf(c, '/etc/nginx/sites-available/mysite')

Load an nginx serverblock from a file:

>>> import nginx
>>> c = nginx.loadf('/etc/nginx/sites-available/testsite')
>>> c.children
[<main.Server object at 0x7f1ed4573890>]
>>> c.server.children
[<main.Comment object at 0x7f1ed45736d0>, <main.Key object at 0x7f1ed4573750>, <main.Key object at 0x7f1ed4573790>, <main.Location object at 0x7f1ed4573850>]
>>> c.as_dict
{'conf': [{'server': [{'#': 'This is a test comment'}, {'server_name': 'localhost'}, {'root': '/srv/http'}, {'location /': [{'allow': 'all'}]}]}]}

Format an nginx serverblock into a string (change the amount of spaces (or tabs) for each indentation level by modifying nginx.INDENT first):

>>> c.servers
[<main.Server object at 0x7f1ed4573890>]
>>> c.as_strings
['server {\n', '    # This is a test comment\n', '    server_name localhost;\n', '    root /srv/http;\n', '\n    location / {\n', '        allow all;\n', '    }\n\n', '}\n']

Find where you put your keys:

>>> import nginx
>>> c = nginx.loadf('/etc/nginx/sites-available/testsite')
>>> c.filter('Server')
[<main.Server object at 0x7f1ed4573890>]
>>> c.filter('Server')[0].filter('Key', 'root')
[<main.Key object at 0x7f1ed4573790>]
>>> c.filter('Server')[0].filter('Location')
[<main.Location object at 0x7f1ed4573850>]

Or just get everything by its type:

>>> import nginx
>>> c = nginx.loadf('/etc/nginx/sites-available/testsite')
>>> c.servers
[<main.Server object at 0x7f1ed4573890>]
>>> c.servers[0].keys
[<main.Key object at 0x7f1ed4573750>, <main.Key object at 0x7f1ed4573790>]
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].