Наверняка вы замечали, что в Python есть удобная функция для получения переменной окружения
os.getenv(NAME)
И её "сестра" для создания или изменения переменных окружения
os.putenv(NAME, VALUE)
Но почему-то putenv() не работает как должно. Энвайромент не обновляется!
os.putenv('MYVAR', '1')
print(os.getenv('MYVAR'))
... и ничего 😴
Почему так?
На самом деле энвайромент обновляется, но это значение не добавляется в словарь os.environ.
Откройте исходник функции os.getenv(). Это просто шорткат для os.environ.get()
В то время как putenv() это built-in С-функция.
Словарь os.environ (или точней класс из MutableMapping) создаётся из энвайромента в момент инициализации. Функция putenv() самостоятельно его не изменяет.
В тоже время, когда вы создаёте или изменяете ключ в os.environ, автоматически вызывается putenv() в методе __setitem__().
То есть, технически putenv() всё делает верно, но в os.environ это не отражается. Можно проверить так:
>>> os.putenv('MYVAR', '123')
>>> os.system('python -c "import os;print(os.getenv(\'MYVAR\'))"')
123
Я объявил переменную в текущем процессе и вызвал дочерний процесс, который её унаследовал и получил в составе os.environ.
Аналогично при удалении переменной вызывается еще одна built-in функция unsetenv(), удаляющая переменную из системы.
Итого
▫️ Удобней всего явно обновлять переменные через os.environ
▫️ Есть способ неявно создать/удалить переменную через putenv/unsetenv, что не повлияет на os.environ но изменит энвайромент и передаст изменения сабпроцессам. Но так лучше не делать!
▫️os.environ это просто обертка для built-in функций putenv() и unsetenv().
#basic
📰 Nginx 1.31 Released with HTTP Forward Proxy Support
Nginx 1.31 introduces HTTP forward proxy support and addresses security vulnerabilities in HTTP/2, HTTP/3, OCSP, and core modules.
🔗 Source: https://linuxiac.com/nginx-1-31-released-with-http-forward-proxy-support/
#nginx
📰 Kubernetes sets a new standard for release notes, also kills Ingress NGINX
Release team explains links between Version 1.36 and classic print The Great Wave off Kanagawa Kubernetes issued a new release called “Haru” on Wednesday, and the release notes and logo might be more interesting than the software.…
🔗 Source: https://go.theregister.com/feed/www.theregister.com/2026/04/23/kubernetes_1_36_haru/
#nginx
📰 I don't use Tailscale or Nginx to access my home lab remotely, here's what I use instead
One of the most useful services to any home labber is a VPN, so that you can access your home network from anywhere and browse as if you're at home. That not only lets you use any self-hosted services you have on your NAS without having to open ports to the wider internet, but it also circumvents any geo-blocked services and nicely encrypts your data, so nobody can snoop in.
🔗 Source: https://www.xda-developers.com/i-dont-use-tailscale-or-nginx-to-access-my-home-lab-remotely-heres-what-i-use-instead/
#nginx
📰 Nginx 1.30 Released With Multipath TCP, ECH & More
Nginx 1.30 was just released as the newest stable version of this popular web server. Nginx 1.30 incorporates all of the changes from the Nginx 1.29.x mainline branch to provide a lot of new functionality like Multipath TCP (MPTCP)...
🔗 Source: https://www.phoronix.com/news/Nginx-1.30-Released
#nginx
📰 Nginx 1.29.7 Delivers Multipath TCP Support
Released this week was Nginx 1.29.7 as the newest mainline version of this HTTP(S) web server. Releasing alongside Nginx 1.28.3 stable, it fixed buffer overflow vulnerabilities and some other vulnerabilities. Making Nginx 1.29.7 more exciting though is that it landed Multipath TCP support...
🔗 Source: https://www.phoronix.com/news/Nginx-1.29.7-Multipath-TCP
#nginx
http://blog.povilasb.com/posts/python-asyncio-vs-nginx-performance/
While I was playing with Python #asyncio I got interested in how well it performs serving data over TLS compared to #Nginx. So I implemented a small HTTPS server with asyncio:
👩💻 Nginx Path Configuration Pitfalls.
• Nginx — это веб-сервер, на котором работает треть всех сайтов в мире. Но если забыть или проигнорировать некоторые ошибки в настройках, можно стать отличной мишенью для атакующих. Благодаря этому материалу, можно понять какие ошибки в конфигурациях встречаются чаще всего и как их исправить.
Attacks:
• Nginx Configuration Vulnerability;
• Exploiting Trailing Slash Misconfiguration;
• Exploiting Parent Directory Access;
• Impact Without Trailing Slash on Alias;
• Combined Impact.
Defend Against Attacks:
• Update Nginx;
• Configuration Check;
• Use Configuration Management;
• Security Headers;
• Access Control;
• Directory Listing;
• Alias Traversal Protection;
• HTTP to HTTPS Redirect;
• SSL Configuration;
• Rate Limiting;
• Connection Limits;
• Custom Error Pages;
• Gzip Compression;
• Client-Side Caching;
• HTTP2 Protocol;
• Secure File Permissions;
• Web Application Firewall (WAF);
• Monitoring and Logging;
• SSH Hardening;
• Firewall Configuration;
• Two-Factor Authentication;
• Regular Backups;
• Deny Hidden Files;
• IP Whitelisting;
• Disable Unused Modules;
• Use Trailing Slash in Alias Directives;
• Regular Expression Matching;
• Implement Strict Location Paths.
#Nginx#devsecops