pythontr.com
Nginx üzerinden bir önceki yazımızda python dosyalarımızın nasıl çalıştıracağımızı görmüştük. Bu örneğimizde ise cache ve session yönetimini göreceğiz. Cachleme yaparken login olan kullanıcılarımızı cachlemeden sayfalar üzerinde gezinmelerini sağlayacağız.
fastcgi_cache_path /var/cache/nginx_pythontr levels=1:2 keys_zone=pythontr:64m max_size=10000m inactive=60m; fastcgi_temp_path /var/cache/nginx_pythontr/tmp;
# POST istekleri ve URL sorgu dizesi ile her zaman php yada python için gitmeli set $skip_cache 0; if ($request_method = POST) { # set $cache_uri 'null cache'; set $skip_cache 1; } if ($query_string != "") { # set $cache_uri 'null cache'; set $skip_cache 1; } # Oturum açmış olan kullanıcılar veya son commenters için önbellek kullanmayın if ($http_cookie ~* "login") { # set $cache_uri 'null cache'; set $skip_cache 1; } location / { rewrite ^/([a-z0-9-_]*)-([0-9]*)$ /haber.py?tid=$2; } location /makale { rewrite ^/makale/([a-z0-9-_]*)-([0-9]*)$ /makale.py?tid=$2; } # anasayfa root çağırıldığında çalışacak dosyaları belirle location = / { index index.py index.html index.htm; } # Diger dosyalari backend sunucudan (Apache'den) al location ~ \.py$ { # cache # set $skip_cache 1; # if ($cache_uri != "null cache") { # set $skip_cache 0; # } fastcgi_cache pythontr; fastcgi_cache_bypass $skip_cache; fastcgi_no_cache $skip_cache; fastcgi_cache_key $scheme$host$request_uri$request_method; fastcgi_cache_valid 300s; fastcgi_cache_valid any 8m; fastcgi_cache_bypass $http_pragma; fastcgi_cache_lock on; fastcgi_ignore_headers X-Accel-Expires Expires Cache-Control Set-Cookie; fastcgi_cache_use_stale error timeout invalid_header updating http_500 http_503; add_header X-Cache $upstream_cache_status; expires 300; # normal ayarlar include /etc/nginx/fastcgi_params; fastcgi_pass unix:/var/run/fcgiwrap.socket; fastcgi_index index.py; #autoindex on; fastcgi_param DOCUMENT_ROOT /home/www/pythontr.com; fastcgi_param SCRIPT_FILENAME /home/www/pythontr.com$fastcgi_script_name; }
Yorumlar