fork download
  1. nginx = '''server {
  2. listen 80;
  3. #SSL
  4. charset utf-8;
  5. root /home/u36/web/basket.com;
  6. index index.html;
  7.  
  8. server_name basket.com www.basket.com;
  9. #ErrorPages
  10. #Redirects
  11. location / {
  12. try_files \$uri \$uri/ /index.html;
  13. }
  14. location ~ /\.ht {
  15. deny all;
  16. }
  17. location ~ \.php$ {
  18. try_files \$uri /index.html =404;
  19. fastcgi_split_path_info ^(.+\.php)(/.+)$;
  20. fastcgi_pass unix:/var/run/php70-vhost_20;
  21. fastcgi_index index.html;
  22. fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
  23. include fastcgi_params;
  24. }
  25. }
  26. '''
  27. oldname = 'basket.com'
  28. newname = 'gogol.ru'
  29. oldcharset = 'utf-8'
  30. newcharset = 'cp-1251'
  31. oldindex = 'index.php'
  32. newindex = 'index.html'
  33. ngreplacement = {
  34. oldname: newname,
  35. oldcharset: newcharset,
  36. oldindex: newindex
  37. }
  38. # работаем с новой строкой, не трогая исходную
  39. newng = nginx
  40. for i, j in ngreplacement.items():
  41. newng = newng.replace(i, j) # заменяем, результат присваиваем в ту же переменную
  42. print(newng)
Success #stdin #stdout 0.02s 28384KB
stdin
Standard input is empty
stdout
server {
        listen   80; 
        #SSL
charset cp-1251;
        root /home/u36/web/gogol.ru; 
        index index.html;

        server_name gogol.ru www.gogol.ru; 
#ErrorPages
#Redirects
        location / {
        try_files \$uri \$uri/ /index.html;
        }
         location ~ /\.ht {
                deny all;
        }
         location ~ \.php$ {
          try_files \$uri /index.html =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php70-vhost_20;
        fastcgi_index index.html;
        fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
        include fastcgi_params;
         }
}