ваш IP: 3.16.51.3

ESPOCRM Правильная настройка NGINX

Среди open source CRM систем, пожалуй самая легковесная и в тоже время функциональная это ESPOCRM. Но к сожалению, как и большинства продуктов, база знаний для разработчиков и администраторов очень скупа. У ESPO тоже при запуске на связке NGINX+PHP-FPM имеется проблема, очень большая проблема! Дело в том, что официальный конфиг тоже не работает и при старте на таких настройках, система просто не грузиться и выдаёт ошибку "bad server response". Причём в логах WEB сервисов и логах самой системы ошибок нет. В общем вот рабочий конфиг:

server {
	server_name <ДОМЕННОЕ ИМЯ> www.<ДОМЕННОЕ ИМЯ>;
	charset UTF-8;
	index index.php index.html;
	disable_symlinks if_not_owner from=$root_path;
	include /etc/nginx/vhosts-includes/*.conf;
	include /etc/nginx/vhosts-resources/<ДОМЕННОЕ ИМЯ>/*.conf;
	access_log /var/www/httpd-logs/<ДОМЕННОЕ ИМЯ>.access.log;
	error_log /var/www/httpd-logs/<ДОМЕННОЕ ИМЯ>.error.log notice;
	ssi on;
	return 301 https://$host:443$request_uri;
	set $root_path /var/www/<ИМЯ ПОЛЬЗОВАТЕЛЯ>/data/www/<ДОМЕННОЕ ИМЯ>;
	root $root_path;
	location / {
	    try_files $uri $uri/ /index.php?$query_string;
		location ~ [^/]\.ph(p\d*|tml)$ {
			try_files /does_not_exists @php;
		}
	}
	
	location /api/v1/ {
        if (!-e $request_filename){
            rewrite ^/api/v1/(.*)$ /api/v1/index.php last; break;
        }
        location ~ [^/]\.ph(p\d*|tml)$ {
            try_files /does_not_exists @php;
        }
    }
    
    location /portal/ {
        try_files $uri $uri/ /portal/index.php?$query_string;
        location ~ [^/]\.ph(p\d*|tml)$ {
            try_files /does_not_exists @php;
        }
    }

    location /api/v1/portal-access {
        if (!-e $request_filename){
            rewrite ^/api/v1/(.*)$ /api/v1/portal-access/index.php last; break;
        }
    }
    location ~ /reset/?$ {
        try_files /reset.html =404;
    }
    location ^~ (data|api)/ {
        if (-e $request_filename){
            return 403;
        }
    }
    location ^~ /data/logs/ {
        deny all;
    }
    location ^~ /data/config.php {
        deny all;
    }
    location ^~ /data/cache/ {
        deny all;
    }
    location ^~ /data/upload/ {
        deny all;
    }
    location ^~ /application/ {
        deny all;
    }
    location ^~ /custom/ {
        deny all;
    }
    location ^~ /vendor/ {
        deny all;
    }
    location ~ /\.ht {
        deny all;
    }
    
    client_max_body_size 50M;
	
	listen <IP АДРЕС СЕРВЕРА v4>:80;
	listen <[IP АДРЕС СЕРВЕРА v6]>:80;
	listen <[IP АДРЕС СЕРВЕРА v6]>:80;
	listen <[IP АДРЕС СЕРВЕРА v6]>:80;
	listen <[IP АДРЕС СЕРВЕРА v6]>:80;
	location @php {
		fastcgi_index index.php;
		fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f crm@<ДОМЕННОЕ ИМЯ>";
		fastcgi_pass unix:/var/www/php-fpm/<ИМЯ ПОЛЬЗОВАТЕЛЯ>.sock;
		fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
		try_files $uri =404;
		include fastcgi_params;
	}
}
server {
	server_name <ДОМЕННОЕ ИМЯ> www.<ДОМЕННОЕ ИМЯ>;
	ssl_certificate "/var/www/httpd-cert/<ИМЯ ПОЛЬЗОВАТЕЛЯ>/<ДОМЕННОЕ ИМЯ>_le2.crtca";
	ssl_certificate_key "/var/www/httpd-cert/<ИМЯ ПОЛЬЗОВАТЕЛЯ>/<ДОМЕННОЕ ИМЯ>_le2.key";
	ssl_ciphers EECDH:+AES256:-3DES:RSA+AES:!NULL:!RC4;
	ssl_prefer_server_ciphers on;
	ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
	add_header Strict-Transport-Security "max-age=31536000;";
	ssl_dhparam /etc/ssl/certs/dhparam4096.pem;
	charset UTF-8;
	index index.php index.html;
	disable_symlinks if_not_owner from=$root_path;
	include /etc/nginx/vhosts-includes/*.conf;
	include /etc/nginx/vhosts-resources/<ДОМЕННОЕ ИМЯ>/*.conf;
	access_log /var/www/httpd-logs/<ДОМЕННОЕ ИМЯ>.access.log;
	error_log /var/www/httpd-logs/<ДОМЕННОЕ ИМЯ>.error.log notice;
	ssi on;
	set $root_path /var/www/<ИМЯ ПОЛЬЗОВАТЕЛЯ>/data/www/<ДОМЕННОЕ ИМЯ>;
	root $root_path;
	location / {
	    try_files $uri $uri/ /index.php?$query_string;
		location ~ [^/]\.ph(p\d*|tml)$ {
			try_files /does_not_exists @php;
		}
	}
	
	location /api/v1/ {
        if (!-e $request_filename){
            rewrite ^/api/v1/(.*)$ /api/v1/index.php last; break;
        }
        location ~ [^/]\.ph(p\d*|tml)$ {
            try_files /does_not_exists @php;
        }
    }
    
    location /portal/ {
        try_files $uri $uri/ /portal/index.php?$query_string;
        location ~ [^/]\.ph(p\d*|tml)$ {
            try_files /does_not_exists @php;
        }
    }

    location /api/v1/portal-access {
        if (!-e $request_filename){
            rewrite ^/api/v1/(.*)$ /api/v1/portal-access/index.php last; break;
        }
    }
    location ~ /reset/?$ {
        try_files /reset.html =404;
    }
    location ^~ (data|api)/ {
        if (-e $request_filename){
            return 403;
        }
    }
    location ^~ /data/logs/ {
        deny all;
    }
    location ^~ /data/config.php {
        deny all;
    }
    location ^~ /data/cache/ {
        deny all;
    }
    location ^~ /data/upload/ {
        deny all;
    }
    location ^~ /application/ {
        deny all;
    }
    location ^~ /custom/ {
        deny all;
    }
    location ^~ /vendor/ {
        deny all;
    }
    location ~ /\.ht {
        deny all;
    }
    
    client_max_body_size 50M;
	
	listen <IP АДРЕС СЕРВЕРА v4>:443 ssl;
	listen <[IP АДРЕС СЕРВЕРА v6]>:443 ssl;
	listen <[IP АДРЕС СЕРВЕРА v6]>:443 ssl;
	listen <[IP АДРЕС СЕРВЕРА v6]>:443 ssl;
	listen <[IP АДРЕС СЕРВЕРА v6]>:443 ssl;
	location @php {
		fastcgi_index index.php;
		fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f crm@<ДОМЕННОЕ ИМЯ>";
		fastcgi_pass unix:/var/www/php-fpm/<ИМЯ ПОЛЬЗОВАТЕЛЯ>.sock;
		fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
		try_files $uri =404;
		include fastcgi_params;
	}
}

Данный конфиг используется для двух сайтов на VDS со следующими характеристиками:

OS Debian 9 x64, NGINX+PHP-FPM, SSL Let's Encrypt, переадресация с www на без www, переадресация с http на https.

Кому интересен хороший и недорогой хостинг VDS рекомендую ServTech

Автор: Master Wenom
18 марта 2019
blog comments powered by Disqus