Настройка NGINX в режиме PHP-FPM для OpenCart/ocStore 2.3

Тема в разделе "Ошибки и их решения", создана пользователем UovoU, 16 дек 2022.

  1. UovoU

    UovoU Новичок

    Сообщения:
    4
    Симпатии:
    1
    Здравствуйте. Делаю новый сайт на ocStore 2.3, версия PHP 7.3 и хочу перейти на PHP FastCGI (Nginx + PHP-FPM), помогите настроить фаил конфига nginx.

    Моя проблема в том что у меня на сайте два языка и добавлена приставка ru и en для разных языков.
    Для этого я использую модуль SEO CMS MULTILANG 2 57.0 (мультиязык / мультирегион)

    Из-за этого такие ссылки не открываются и выдают ошибку 404:
    domain.ru/ru/index.php?route=common/currency/currency
    domain.ru/en/index.php?route=common/currency/currency

    Если убираю приставку ru и en то все работает.
    domain.ru/index.php?route=common/currency/currency - такая ссылка открывается.

    Еще пример:
    domain.ru/ru/index.php?route=information/information&information_id=4 - не открывается, выдает ошибку 404
    Если убираю приставку ru то domain.ru/index.php?route=information/information&information_id=4 открывается

    Если ставлю обработчик PHP CGI 7.3 то все работает так что дело не в модуле.

    Код конфига:
    Код:
    server {
        server_name domain.ru www.domain.ru;
        charset off;
        index index.php index.html;
        disable_symlinks if_not_owner from=$root_path;
        include /etc/nginx/vhosts-includes/*.conf;
        include /etc/nginx/vhosts-resources/domain.ru/*.conf;
        access_log /var/www/httpd-logs/domain.ru.access.log;
        error_log /var/www/httpd-logs/domain.ru.error.log notice;
        set $root_path /var/www/user/data/www/domain.ru;
        root $root_path;
        
    location / {
        #Редирект с без www на www
        if ($http_host ~ "^domain.ru"){
        rewrite ^(.*)$ https://www.domain.ru$1 redirect;
        }
        
        if (!-e $request_filename){
        rewrite ^/(.+)$ /index.php?_route_=$1 last;
        }
    
        location ~ [^/]\.ph(p\d*|tml)$ {
            try_files /does_not_exists @php;
        }
    
        location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
            expires 365d;
        }
    }
    
        location @php {
            fastcgi_index index.php;
            fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f admin@domain.ru";
            fastcgi_pass unix:/var/www/php-fpm/3.sock;
            fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
            try_files $uri =404;
            include fastcgi_params;
        }
        return 301 https://$host:443$request_uri;
        ssi on;
        listen 185.197.160.60:80;
    }
    server {
        server_name domain.ru www.domain.ru;
        ssl_certificate "/var/www/httpd-cert/user/domain.ru_le1.crtca";
        ssl_certificate_key "/var/www/httpd-cert/user/domain.ru_le1.key";
        ssl_ciphers EECDH:+AES256:-3DES:RSA+AES:!NULL:!RC4;
        ssl_prefer_server_ciphers on;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
        ssl_dhparam /etc/ssl/certs/dhparam4096.pem;
        charset off;
        index index.php index.html;
        disable_symlinks if_not_owner from=$root_path;
        include /etc/nginx/vhosts-includes/*.conf;
        include /etc/nginx/vhosts-resources/domain.ru/*.conf;
        access_log /var/www/httpd-logs/domain.ru.access.log;
        error_log /var/www/httpd-logs/domain.ru.error.log notice;
        set $root_path /var/www/user/data/www/domain.ru;
        root $root_path;
    
    location / {
        #Редирект с без www на www
        if ($http_host ~ "^domain.ru"){
        rewrite ^(.*)$ https://www.domain.ru$1 redirect;
        }
        
        if (!-e $request_filename){
        rewrite ^/(.+)$ /index.php?_route_=$1 last;
        }
    
        location ~ [^/]\.ph(p\d*|tml)$ {
            try_files /does_not_exists @php;
        }
    
        location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
            expires 365d;
        }
    }
    
        location @php {
            fastcgi_index index.php;
            fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f admin@domain.ru";
            fastcgi_pass unix:/var/www/php-fpm/3.sock;
            fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
            try_files $uri =404;
            include fastcgi_params;
        }
        add_header Strict-Transport-Security "max-age=31536000;";
        ssi on;
        listen 185.197.160.60:443 ssl;
    }
     
  2. Sig

    Sig Пользователь

    Сообщения:
    89
    Симпатии:
    25
    Не уверен в правоте, не работал с этом модулем, но такие ссылки и не должны открываться.
    Включите в настройках магазина SEO URL, тогда должна заработать адресация с учетом языка.
     
  3. UovoU

    UovoU Новичок

    Сообщения:
    4
    Симпатии:
    1
    SEO URL включен.
    domain.ru/ru/index.php?route=common/currency/currency
    domain.ru/en/index.php?route=common/currency/currency
    это ссылки смены валюты. Если меняю валюту то ошибка 404.

    Разработчик модуля говорит что это не верная настройка config nginx.
    Если ставлю обработчик PHP CGI 7.3 то все работает так что дело не в модуле.
     
  4. Sig

    Sig Пользователь

    Сообщения:
    89
    Симпатии:
    25
    А разработчик говорит что такой адрес нормальный?
    domain.ru/en/index.php?route=common/currency/currency
    Тут просто смесь получается ЧПУ от языка и не ЧПУ ссылки.
    NGINX её преобразует в обращение на адрес
    domain.ru/index.php?_route_=/en/index.php?route=common/currency/currency
    Далее роутер Опенкарта должен разобрать этот URL, но так как там смесь ежа с ужом, он отвечает 404 ошибкой

    Как у вас формируются ссылки на товары в разных языках?
     
  5. UovoU

    UovoU Новичок

    Сообщения:
    4
    Симпатии:
    1
    Sig, разработчик модуля SEO CMS MULTILANG 2 57.0 (мультиязык / мультирегион) говорит что это не верная настройка config nginx. Адрес скорее всего не нормальный из-за не правильной настройки nginx.
    Код:
    location / {
    try_files $uri $uri/ @opencart;
    location ~ [^/]\.ph(p\d*|tml)$ {
    if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?_route_=$1 last; }
    try_files /does_not_exists @php;
    }
    ...
    }
    
    location @opencart {
    rewrite ^/(.+)$ /index.php?_route_=$1 last;
    }
    Вот такой вариант мне подсказали на другом форуме. Вроде все работает без ошибок, если найду ошибки то отпишусь в теме.
     
    Ravilr нравится это.
  6. Sig

    Sig Пользователь

    Сообщения:
    89
    Симпатии:
    25
    А можете весь итоговый конфиг показать?
     
  7. UovoU

    UovoU Новичок

    Сообщения:
    4
    Симпатии:
    1
    Прошу прощения за долгий ответ, приболел а потом праздники.
    Вот полный конфиг, ошибок пока не было:

    Код:
    server {
        server_name domain.ru www.domain.ru;
        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/domain.ru/*.conf;
        access_log /var/www/httpd-logs/domain.ru.access.log;
        error_log /var/www/httpd-logs/domain.ru.error.log notice;
        set $root_path /var/www/user/data/www/domain.ru;
        root $root_path;
        
    location / {
        #Редирект с без www на www
        if ($http_host ~ "^domain.ru"){
            rewrite ^(.*)$ https://www.domain.ru$1 redirect;
        }   
        try_files $uri $uri/ @opencart;
        location ~ [^/]\.ph(p\d*|tml)$ {
            if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?_route_=$1 last; }
            try_files /does_not_exists @php;
        }
        location ~* \.(log|tpl|txt|twig|xml|ini)$ {
            deny all;
        }
        location ~ /\. {
            deny all;
        }
        location ~ ^/system/ {
            deny all;
        }
        location = /robots.txt {
            allow all;
        }
        location = /sitemap.xml {
            allow all;
            rewrite ^/(.*)$ /ru/sitemap last;
        }
        location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
            expires 365d;
        }
    }
    
        location @opencart {
        rewrite ^/(.+)$ /index.php?_route_=$1 last;
        }
    
        location @php {
            fastcgi_index index.php;
            fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f admin@domain.ru";
            fastcgi_pass unix:/var/www/php-fpm/3.sock;
            fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
            try_files $uri =404;
            include fastcgi_params;
        }
        return 301 https://$host:443$request_uri;
        ssi on;
        listen 185.197.160.60:80;
    }
    server {
        server_name domain.ru www.domain.ru;
        ssl_certificate "/var/www/httpd-cert/user/domain.ru_le1.crtca";
        ssl_certificate_key "/var/www/httpd-cert/user/domain.ru_le1.key";
        ssl_ciphers EECDH:+AES256:-3DES:RSA+AES:!NULL:!RC4;
        ssl_prefer_server_ciphers on;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
        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/domain.ru/*.conf;
        access_log /var/www/httpd-logs/domain.ru.access.log;
        error_log /var/www/httpd-logs/domain.ru.error.log notice;
        set $root_path /var/www/user/data/www/domain.ru;
        root $root_path;
    
    location / {
        #Редирект с без www на www
        if ($http_host ~ "^domain.ru"){
            rewrite ^(.*)$ https://www.domain.ru$1 redirect;
        }   
        try_files $uri $uri/ @opencart;
        location ~ [^/]\.ph(p\d*|tml)$ {
            if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?_route_=$1 last; }
            try_files /does_not_exists @php;
        }
        location ~* \.(log|tpl|txt|twig|xml|ini)$ {
            deny all;
        }
        location ~ /\. {
            deny all;
        }
        location ~ ^/system/ {
            deny all;
        }
        location = /robots.txt {
            allow all;
        }
        location = /sitemap.xml {
            allow all;
            rewrite ^/(.*)$ /ru/sitemap last;
        }
        location ~* ^.+\.(jpg|jpeg|gif|png|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf)$ {
            expires 365d;
        }
    }
    
        location @opencart {
        rewrite ^/(.+)$ /index.php?_route_=$1 last;
        }
    
        location @php {
            fastcgi_index index.php;
            fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f admin@domain.ru";
            fastcgi_pass unix:/var/www/php-fpm/3.sock;
            fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
            try_files $uri =404;
            include fastcgi_params;
        }
        add_header Strict-Transport-Security "max-age=31536000;";
        ssi on;
        listen 185.197.160.60:443 ssl;
    }