Страница 1 из 2

Конфиг для Nginx

Добавлено: 29.03.2016, 14:24
natalya
Добрый день! Можете ли вы предоставить конфиг реврайтов для Nginx?

Добавлено: 29.03.2016, 15:12
simplamarket
natalya писал(а):Добрый день! Можете ли вы предоставить конфиг реврайтов для Nginx?
Добрый день, Вы имеете в виду настройку сервера ?
Если да, то вот эта статья может быть полезна http://nginx.org/ru/docs/http/ngx_http_rewrite_module.html

Добавлено: 10.04.2016, 13:32
natalya
Конфиг от симлы не подходит, выходит 500 ошибка. Помогите пожалуйста.

Добавлено спустя 1 час 42 минуты:
Ошибка 500 пропала, теперь косяк с фильтрами, выбрасывает 404 станицу.

Добавлено: 10.04.2016, 18:48
simplamarket
natalya писал(а):Конфиг от симлы не подходит, выходит 500 ошибка. Помогите пожалуйста.


Ошибка 500 пропала, теперь косяк с фильтрами, выбрасывает 404 станицу.

Проверьте включен ли у Вас на сервере mod_rewrite
он отвечает за htaccess
кроме того, посмотрите на права на сам файл htacces

Добавлено: 11.04.2016, 01:37
natalya
Установлен Nginx, поддержка htaccess отсутствует. Нужен rewrite для products

Добавлено: 11.04.2016, 06:18
simplamarket
natalya писал(а):Установлен Nginx, поддержка htaccess отсутствует. Нужен rewrite для products

У вас локальный сервер или удаленный? давайте свяжемся для того что бы прояснить эту ситуацию.
Напишите нам в скайп, так будет быстрей.
Скайп simplamarket

Добавлено: 11.04.2016, 06:22
zyxer
Было бы здорово увидеть phpinfo(). В идеале ссылку на файл который выводит (если сервак в сети).

Добавлено: 12.04.2016, 15:14
natalya
Рабочий конфиг для Nginx

Код: Выделить всё

server {
   listen          80;
   server_name     site.ru www.site.ru;
   root /var/www/site.ru/html;
   index index.php;
   client_max_body_size 64M;

   access_log off;
   
   
   
   

   location = /favicon.ico {
         log_not_found off;
         access_log off;
   }

   location = /robots.txt {
         allow all;
         log_not_found off;
         access_log off;
   }

   location  \.(txt|log)$ {
         allow 192.168.0.0/16;
         deny all;
   }

   

      
      
      
      location /backend {
       
      
      index index.php;
      
      location ~ \.php$ {
               try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_pass   unix:/var/run/php5-fpm.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include fastcgi_params;
                fastcgi_ignore_client_abort on;
                fastcgi_param  SERVER_NAME $http_host;
        }
      
      
      
   }
   
   
      
      
      
      
      
   rewrite   ^/admin/?$  /backend last;
   
   location ~* ^/(api|cache|compiled|config|design/(.*)/html|payment|Smarty|view)/(.*) { deny all; }

   location / {
         try_files $uri @rewrite;
   }

   
   
   
   
   location @rewrite {
      rewrite ^/catalog/([^/]+)/?$   index.php?module=ProductsView&category=$1;
      rewrite ^/catalog/([^/]+)   index.php?module=ProductsView&category=$1;
      rewrite ^/catalog/([^/]+)/([^/]+)/?$   index.php?module=ProductsView&category=$1&brand=$2;
      rewrite ^/products/([^/]+)/?$   index.php?module=ProductView&product_url=$1;
      rewrite ^/products/?$   index.php?module=ProductsView;
      rewrite ^/all-products/?$   index.php?module=ProductsView;
      rewrite ^/brands/([^/]+)/?$   index.php?module=ProductsView&brand=$1;
      rewrite ^/brands/([^/]+)/page_([^/]+)/?$   index.php?module=ProductsView&brand=$1&page=$2;
      rewrite ^/search/([^/]+)/?$   index.php?module=ProductsView&keyword=$1;
      rewrite ^/search/?$   index.php?module=ProductsView;
      rewrite ^/blog/([^/]+)/?$   index.php?module=BlogView&url=$1;
      rewrite ^/blog/?$   index.php?module=BlogView;
      rewrite ^/wishlist/([^/]+)/?$   index.php?module=WishlistView&id=$2&lang_label=$1;
      rewrite ^/wishlist/?$   index.php?module=WishlistView&lang_label=$1;
      rewrite ^/wishlist/delete/?$   index.php?module=WishlistView&id=$1&action=delete;
      rewrite ^/comparison/?$   index.php?module=ComparisonView;
      rewrite ^/cart/?$   index.php?module=CartView;
      rewrite ^/cart/([^/]+)/?$   index.php?module=CartView&add_variant=$1;
      rewrite ^/cart/remove/([^/]+)/?$   index.php?module=CartView&delete_variant=$1;
      rewrite ^/order/([^/]+)/?$   index.php?module=OrderView&url=$1;
      rewrite ^/order/?$   index.php?module=OrderView;
      rewrite ^/user/login/?$   index.php?module=LoginView;
      rewrite ^/user/register/?$   index.php?module=RegisterView;
      rewrite ^/user/logout/?$   index.php?module=LoginView&action=logout;
      rewrite ^/user/password_remind/?$   index.php?module=LoginView&action=password_remind;
      rewrite ^/user/password_remind/([0-9a-z]+)/?$   index.php?module=LoginView&action=password_remind&code=$1;
      rewrite ^/user/?$   index.php?module=UserView;
      rewrite ^/sitemap.xml?$   sitemap.php last;
      rewrite ^/yandex.xml?$   yandex.php last;
      rewrite ^/contact/?$   index.php?module=FeedbackView;
      rewrite ^/order/([^/]+)/([^/]+)/?$   index.php?module=OrderView&url=$1&file=$2;
      if (!-f $request_filename){
         set $rule_26 1$rule_26;
      }
      if (!-d $request_filename){
         set $rule_26 2$rule_26;
      }
      if ($rule_26 = "21"){
         rewrite ^/([^/]+)/?$ /index.php?module=PageView&page_url=$1;
      }
      rewrite ^/?$ /index.php?module=MainView&page_url=;
      
      rewrite ^ /index.php;
   }

   location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_pass   unix:/var/run/php5-fpm.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include fastcgi_params;
                fastcgi_ignore_client_abort on;
                fastcgi_param  SERVER_NAME $http_host;
        }

   location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
if (!-e $request_filename){
rewrite ^/files/products/(.+) /resize/resize.php?file=$1&token=$query_string;
}
}
   
   
   
}


В папке /backend/ajax удалить index.php и добавить во все файлы

Код: Выделить всё

session_start();
    chdir('../../');
   require_once('api/Okay.php');
   $okay = new Okay();

Добавлено: 13.04.2016, 06:08
simplamarket
natalya писал(а):Рабочий конфиг для Nginx

Код: Выделить всё

server {
   listen          80;
   server_name     site.ru www.site.ru;
   root /var/www/site.ru/html;
   index index.php;
   client_max_body_size 64M;

   access_log off;
   
   
   
   

   location = /favicon.ico {
         log_not_found off;
         access_log off;
   }

   location = /robots.txt {
         allow all;
         log_not_found off;
         access_log off;
   }

   location  \.(txt|log)$ {
         allow 192.168.0.0/16;
         deny all;
   }

   

      
      
      
      location /backend {
       
      
      index index.php;
      
      location ~ \.php$ {
               try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_pass   unix:/var/run/php5-fpm.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include fastcgi_params;
                fastcgi_ignore_client_abort on;
                fastcgi_param  SERVER_NAME $http_host;
        }
      
      
      
   }
   
   
      
      
      
      
      
   rewrite   ^/admin/?$  /backend last;
   
   location ~* ^/(api|cache|compiled|config|design/(.*)/html|payment|Smarty|view)/(.*) { deny all; }

   location / {
         try_files $uri @rewrite;
   }

   
   
   
   
   location @rewrite {
      rewrite ^/catalog/([^/]+)/?$   index.php?module=ProductsView&category=$1;
      rewrite ^/catalog/([^/]+)   index.php?module=ProductsView&category=$1;
      rewrite ^/catalog/([^/]+)/([^/]+)/?$   index.php?module=ProductsView&category=$1&brand=$2;
      rewrite ^/products/([^/]+)/?$   index.php?module=ProductView&product_url=$1;
      rewrite ^/products/?$   index.php?module=ProductsView;
      rewrite ^/all-products/?$   index.php?module=ProductsView;
      rewrite ^/brands/([^/]+)/?$   index.php?module=ProductsView&brand=$1;
      rewrite ^/brands/([^/]+)/page_([^/]+)/?$   index.php?module=ProductsView&brand=$1&page=$2;
      rewrite ^/search/([^/]+)/?$   index.php?module=ProductsView&keyword=$1;
      rewrite ^/search/?$   index.php?module=ProductsView;
      rewrite ^/blog/([^/]+)/?$   index.php?module=BlogView&url=$1;
      rewrite ^/blog/?$   index.php?module=BlogView;
      rewrite ^/wishlist/([^/]+)/?$   index.php?module=WishlistView&id=$2&lang_label=$1;
      rewrite ^/wishlist/?$   index.php?module=WishlistView&lang_label=$1;
      rewrite ^/wishlist/delete/?$   index.php?module=WishlistView&id=$1&action=delete;
      rewrite ^/comparison/?$   index.php?module=ComparisonView;
      rewrite ^/cart/?$   index.php?module=CartView;
      rewrite ^/cart/([^/]+)/?$   index.php?module=CartView&add_variant=$1;
      rewrite ^/cart/remove/([^/]+)/?$   index.php?module=CartView&delete_variant=$1;
      rewrite ^/order/([^/]+)/?$   index.php?module=OrderView&url=$1;
      rewrite ^/order/?$   index.php?module=OrderView;
      rewrite ^/user/login/?$   index.php?module=LoginView;
      rewrite ^/user/register/?$   index.php?module=RegisterView;
      rewrite ^/user/logout/?$   index.php?module=LoginView&action=logout;
      rewrite ^/user/password_remind/?$   index.php?module=LoginView&action=password_remind;
      rewrite ^/user/password_remind/([0-9a-z]+)/?$   index.php?module=LoginView&action=password_remind&code=$1;
      rewrite ^/user/?$   index.php?module=UserView;
      rewrite ^/sitemap.xml?$   sitemap.php last;
      rewrite ^/yandex.xml?$   yandex.php last;
      rewrite ^/contact/?$   index.php?module=FeedbackView;
      rewrite ^/order/([^/]+)/([^/]+)/?$   index.php?module=OrderView&url=$1&file=$2;
      if (!-f $request_filename){
         set $rule_26 1$rule_26;
      }
      if (!-d $request_filename){
         set $rule_26 2$rule_26;
      }
      if ($rule_26 = "21"){
         rewrite ^/([^/]+)/?$ /index.php?module=PageView&page_url=$1;
      }
      rewrite ^/?$ /index.php?module=MainView&page_url=;
      
      rewrite ^ /index.php;
   }

   location ~ \.php$ {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                fastcgi_pass   unix:/var/run/php5-fpm.sock;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include fastcgi_params;
                fastcgi_ignore_client_abort on;
                fastcgi_param  SERVER_NAME $http_host;
        }

   location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
if (!-e $request_filename){
rewrite ^/files/products/(.+) /resize/resize.php?file=$1&token=$query_string;
}
}
   
   
   
}


В папке /backend/ajax удалить index.php и добавить во все файлы

Код: Выделить всё

session_start();
    chdir('../../');
   require_once('api/Okay.php');
   $okay = new Okay();


Большое спасибо! Надо будет тестировать

Добавлено: 21.07.2016, 18:47
therion.kiev
Поправка для ресайза картинок (то что выше у меня не работало)
******.conf:

Код: Выделить всё

        location ~* ^.+\.(png|jpg|jpeg|gif)$ {
                if (!-e $request_filename){
                rewrite ^/files/(.+)/(.*)$ /resize/resize.php?object=$1&file=$2&token=$query_string;
                }
        }

Добавлено: 10.10.2017, 22:01
anton_slim
natalya писал(а):Рабочий конфиг для Nginx

В папке /backend/ajax удалить index.php и добавить во все файлы

Код: Выделить всё

session_start();
    chdir('../../');
   require_once('api/Okay.php');
   $okay = new Okay();

Нахрена так делать ? Достаточно в конфиг дописать

Код: Выделить всё

   rewrite ^/backend/ajax/([^/]+)\.php$ /backend/ajax/index.php?file=$1 last;


и не надо ничего править в php файлах, проверил работает...

Добавлено: 24.01.2018, 11:44
Slik
Добрый день.

Можете выложить реально рабочий конфиг для Nginx.

Тот что выше не совсем корректно отрабатывает.

Версия ПО

Код: Выделить всё

nginx version: nginx/1.12.2


Код: Выделить всё

 php -v
PHP 5.6.32 (cli) (built: Jan 23 2018 16:06:32)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

Добавлено: 02.04.2019, 01:14
WarmLab
Добрый день, а можно новый конфиг выложить ?
в версии 2.3.2 htaccess изменён ....

Добавлено: 03.04.2019, 11:47
zyxer
не проверял, но все и так должно работать. Или что-то не работает?

Добавлено: 03.04.2019, 14:32
WarmLab
zyxer писал(а):не проверял, но все и так должно работать. Или что-то не работает?

работает но в новой версии реврайты что то убрано что то добавлено новое

Добавлено спустя 40 секунд:
ну например

Код: Выделить всё

RewriteRule ^([a-z]{2}/)?products/([^/]+)/?$   index.php?module=ProductView&product_url=$2&lang_label=$1 [L,QSA]
RewriteRule ^([a-z]{2}/)?all-products/?$       index.php?module=ProductsView&lang_label=$1 [L,QSA]
RewriteRule ^([a-z]{2}/)?all-products/([^/]+)   index.php?module=ProductsView&lang_label=$1&page_url=all-products [L,QSA]

RewriteRule ^([a-z]{2}/)?(discounted|bestsellers)/?$       index.php?module=ProductsView&lang_label=$1&mode=$2 [L,QSA]
RewriteRule ^([a-z]{2}/)?(discounted|bestsellers)/([^/]+)   index.php?module=ProductsView&lang_label=$1&page_url=$2&mode=$2 [L,QSA]

Добавлено: 04.04.2019, 16:07
WarmLab
так кто то поможет перевести новый конфиг?

Добавлено: 05.04.2019, 06:39
zyxer
Там одно было сделано только для оптимизации файла .htaccess (на логику не влияет, просто уменьшение кол-ва строк). Второе, это убраны некоторые параметры. Но если они у вас останутся, это вообще ни на что не влияет. Поэтому рекомендую Вам не трогать то, что и так работает ))

Добавлено: 09.12.2020, 13:20
prihod
OkayCMS версия 3.8
nginx version: nginx/1.16.1
Сам конфиг:

Код: Выделить всё

server {
   server_name nginx.starkbud.com.ua www.nginx.starkbud.com.ua;
   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/nginx.starkbud.com.ua/*.conf;
   access_log /var/www/httpd-logs/nginx.starkbud.com.ua.access.log;
   error_log /var/www/httpd-logs/nginx.starkbud.com.ua.error.log notice;
   ssi on;
   return 301 https://$host:443$request_uri;
   set $root_path /var/www/www-root/data/www/nginx.starkbud.com.ua;
   root $root_path;

   location = /favicon.ico {
       log_not_found off;
       access_log off;
   }

   location = /robots.txt {
       allow all;
       log_not_found off;
       access_log off;
   }

   location / {
      try_files $uri $uri/ /index.php?$args;
   }
   location ~* ^.+\.(png|jpg|jpeg|gif)$ {
         if (!-e $request_filename){
         rewrite ^/files/(.+)/(.*)$ /resize/resize.php?object=$1&file=$2&token=$query_string;
         }
   }
   
   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 max;
   }

   location ~ \.php$ {
      fastcgi_index index.php;
      fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f webmaster@nginx.starkbud.com.ua";
      fastcgi_pass unix:/var/www/php-fpm/www-root.sock;
      fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
      try_files $uri =404;
      include fastcgi_params;
   }
   location @php {
      fastcgi_index index.php;
      fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f webmaster@nginx.starkbud.com.ua";
      fastcgi_pass unix:/var/www/php-fpm/www-root.sock;
      fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
      try_files $uri =404;
      include fastcgi_params;
   }
   listen 185.197.163.8:80;
   gzip on;
   gzip_comp_level 6;
   gzip_disable "msie6";
   gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
}
server {
   server_name nginx.starkbud.com.ua www.nginx.starkbud.com.ua;
   ssl_certificate "/var/www/httpd-cert/www-root/nginx.starkbud.com.ua_le1.crtca";
   ssl_certificate_key "/var/www/httpd-cert/www-root/nginx.starkbud.com.ua_le1.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 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/nginx.starkbud.com.ua/*.conf;
   access_log /var/www/httpd-logs/nginx.starkbud.com.ua.access.log;
   error_log /var/www/httpd-logs/nginx.starkbud.com.ua.error.log notice;
   ssi on;
   set $root_path /var/www/www-root/data/www/nginx.starkbud.com.ua;
   root $root_path;

   location = /favicon.ico {
         log_not_found off;
         access_log off;
   }

   location = /robots.txt {
         allow all;
         log_not_found off;
         access_log off;
   }

   location / {
      try_files $uri $uri/ /index.php?$args;
   }
   
   location ~* ^.+\.(png|jpg|jpeg|gif)$ {
         if (!-e $request_filename){
         rewrite ^/files/(.+)/(.*)$ /resize/resize.php?object=$1&file=$2&token=$query_string;
         }
   }
   
   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 max;
   }
   
   location ~ \.php$ {
      fastcgi_index index.php;
      fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f webmaster@nginx.starkbud.com.ua";
      fastcgi_pass unix:/var/www/php-fpm/www-root.sock;
      fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
      try_files $uri =404;
      include fastcgi_params;
   }
   location @php {
      fastcgi_index index.php;
      fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f webmaster@nginx.starkbud.com.ua";
      fastcgi_pass unix:/var/www/php-fpm/www-root.sock;
      fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$;
      try_files $uri =404;
      include fastcgi_params;
   }
   listen 185.197.163.8:443 ssl;
   gzip on;
   gzip_comp_level 6;
   gzip_disable "msie6";
   gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
}

но есть проблема со скриптами и изображениями
http://prntscr.com/vz0no8
http://prntscr.com/vz0ldk
http://prntscr.com/vz0m5i
пациент starkbud com ua

Буду признателен за совет либо свежий конфиг

Добавлено: 09.12.2020, 14:03
zyxer
https://github.com/OkayCMS/Okay3/blob/master/docs/nginx/nginx.conf
В частности вам нужно смотреть на

Код: Выделить всё

location ~* /(\w+/)?(\w+/)?(.+\.(jpg|jpeg|gif|png|webp|svg|js|css|mp3|ogg|mpe?g|avi|zip|gz|bz2?|rar|swf|woff|woff2|ttf|xls|xlsx|doc|docx|pdf))$ {
            try_files $uri $uri/ /$2$3 /$3 /index.php?$args;
            allow all;
            access_log off;
            expires max;
            add_header Cache-Control public;
            add_header Access-Control-Allow-Origin *;
        }


Там нужно передавать на бек обработку js файлов, если их нет (Эти два скрипта генерятся http://prntscr.com/vz1qx1, их реально нет)

Добавлено: 17.08.2021, 13:30
Slik
Добрый день.
Есть ли у кого то корректный конфиг nginx для текущей версии 4.1.1 ?

Сейчас конкретно есть такая ошибка

Код: Выделить всё

"GET /ajax/cart_ajax.php?action=add_citem&variant_id=179&amount=1 HTTP/1.1" 404


Это при добавлении товара в корзину.