project:apache-nginx-config-generator
Генератор файлов конфигураций для Apache2, Nginx
run.sh - Скрипт для запуска создания файлов и перезапуска Nginx, Apache2:
#!/bin/sh cd /home/admin/www/_default/ php /home/admin/www/_default/conf.php /etc/init.d/nginx restart /etc/init.d/apache2 restart echo "The end"
domains.txt - список доменов:
домен1.ru домен2.ru домен3.ru
conf.php - Генератор конфигов на PHP:
<?php $domains = explode("\n", file_get_contents("domains.txt")); $tmpl_apache=' <VirtualHost *:81> ServerAdmin webmaster@localhost ServerName _host_ ServerAlias www._host_ <IfModule mpm_itk_module> AssignUserId admin www-data </IfModule> DocumentRoot /home/admin/www/_host_/ <Directory /home/admin/www/_host_> Options Indexes FollowSymLinks All MultiViews AllowOverride All </Directory> ErrorLog /home/admin/logs/_host_-error_log </VirtualHost> '; $tmpl_nginx = ' server { listen 80; server_name ##domain## ##domain_aliases##; location /block.png { gzip off; default_type image/png; root /home/##user##/www/##domain##; } location ~* ^.+\.(swf|xml|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|wav|bmp|rtf|js|ods|arj|htc|avi|mpg|mp3|mid)$ { valid_referers none blocked server_names ~\.google\. images.yandex.ru; if ($invalid_referer) { return 404; #rewrite /(.*)\.(gif|jpg|jpeg|png)$ / break; #rewrite ^(.*)$ /block.png break; } root /home/##user##/www/##domain##; } location ~ \.flv$ { root /home/##user##/www/##domain##; flv; } location / { proxy_pass http://127.0.0.1:81; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Accel-Internal /internal_xxx; proxy_set_header Host $http_host; proxy_redirect http://##domain##:81/ /; } location ~ /\.htp { deny all; } location ~ /\.hta { deny all; } location ~ /\.svn { deny all; } location /stub_status { stub_status on; access_log off;} } '; foreach($domains as $d) { if(strlen($d)>3) { $d = strtolower(trim($d)); $path = "/home/admin/www/".$d."/"; if(!file_exists($path))mkdir($path, 0755); $domain_aliases = "www.".$d; $user="admin"; //##domain## ##domain_aliases## $s = str_replace("_host_",$d,$tmpl_apache); $n = str_replace("##user##",$user,$tmpl_nginx); $n = str_replace("##domain##",$d,$n); $n = str_replace("##domain_aliases##",$domain_aliases,$n); //echo $s; $app_conf.=$s; $nginx_conf.=$n; } } echo file_put_contents("../apache_sites.conf", $app_conf); echo file_put_contents("../nginx_sites.conf", $nginx_conf); echo "ok";
project/apache-nginx-config-generator.txt · Последнее изменение: 2017/03/23 21:59 — 127.0.0.1