У минулій статті, я вже говорив про те, що перейшов з віртуального хостингу на віртуальний сервер. У тій же статті, я писав про те, як налаштувати роботу NGINX для нормального функціонування WordPress, використовуючи при цьому, панель управління ISPmanager. У цій же статті, мова піде про те: як налаштувати nginx для роботи з openacart, а саме з SEO pro, так як зі звичайними адресами і так все працює з коробки.
І так, переходимо www-домени, виділяємо цікавлячий нас домен і натискаємо на “конфіг”. Тут ми бачимо файл конфігурації, який для нас створила панель ISPmanager. Він в принципі, працює, але тільки в тому випадку, якщо ви не використовуєте ЧПУ (людино зрозумілі посилання). А для того, щоб працював і з ЧПУ, нам потрібно щось прописати.
Після рядка:
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;прописуємо це:
location / { rewrite ^/sitemap.xml$ /index.php?route=feed/google_sitemap last; rewrite ^/googlebase.xml$ /index.php?route=feed/google_base last; rewrite ^/system/download/(.*) /index.php?route=error/not_found last; if (!-f $request_filename){ set $rule_3 1$rule_3; } if (!-d $request_filename){ set $rule_3 2$rule_3; } if ($uri !~ ".*.(ico|gif|jpg|jpeg|png|js|css)"){ set $rule_3 3$rule_3; } if ($rule_3 = "321"){ rewrite ^/([^?]*) /index.php?_route_=$1 last; } }Ось власне і все!
Можливо в когось щось не вийде і він захоче вивчити мій повністю робочий файл конфігурації:
<span data-mce-type="bookmark" style="display: inline-block; width: 0px; overflow: hidden; line-height: 0;" class="mce_SELRES_start"></span>server { server_name site.com.ua www.site.com.ua; charset off; index index.html index.php; disable_symlinks if_not_owner from=$root_path; include /etc/nginx/vhosts-includes/*.conf; include /etc/nginx/vhosts-resources/site.com.ua/*.conf; #return 301 https://$host:443$request_uri; return 301 https://site.com.ua$request_uri ; error_log /dev/null crit; set $root_path /var/www/ivan/data/www/site.com.ua; root $root_path; listen 185.145.41.55:80; gzip on; gzip_comp_level 9; 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; location / { rewrite ^/sitemap.xml$ /index.php?route=feed/google_sitemap last; rewrite ^/googlebase.xml$ /index.php?route=feed/google_base last; rewrite ^/system/download/(.*) /index.php?route=error/not_found last; if (!-f $request_filename){ set $rule_3 1$rule_3; } if (!-d $request_filename){ set $rule_3 2$rule_3; } if ($uri !~ ".*.(ico|gif|jpg|jpeg|png|js|css)"){ set $rule_3 3$rule_3; } if ($rule_3 = "321"){ rewrite ^/([^?]*) /index.php?_route_=$1 last; } } access_log off; expires max; location ~ [^/]\.php(/|$) { fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; if (!-f $document_root$fastcgi_script_name) { return 404; } fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f [email protected]"; fastcgi_pass unix:/var/www/php-fpm/ivan.sock; fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$; try_files $uri =404; fastcgi_index index.php; include /etc/nginx/fastcgi_params; } } server { server_name site.com.ua www.site.com.ua; if ($host ~* ^www.site.com.ua$) { return 301 $scheme://site.com.ua$request_uri; } ssl on; ssl_certificate "/var/www/httpd-cert/ivan/site.com.ua.crt"; ssl_certificate_key "/var/www/httpd-cert/ivan/site.com.ua.key"; ssl_ciphers EECDH:+AES256:-3DES:RSA+AES:RSA+3DES:!NULL:!RC4:!RSA+3DES; ssl_prefer_server_ciphers on; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; add_header Strict-Transport-Security "max-age=31536000;"; charset off; index index.html index.php; disable_symlinks if_not_owner from=$root_path; include /etc/nginx/vhosts-includes/*.conf; include /etc/nginx/vhosts-resources/site.com.ua/*.conf; error_log /dev/null crit; set $root_path /var/www/ivan/data/www/site.com.ua; root $root_path; listen 185.145.41.55:443; gzip on; gzip_comp_level 9; 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; location / { rewrite ^/sitemap.xml$ /index.php?route=feed/google_sitemap last; rewrite ^/googlebase.xml$ /index.php?route=feed/google_base last; rewrite ^/system/download/(.*) /index.php?route=error/not_found last; if (!-f $request_filename){ set $rule_3 1$rule_3; } if (!-d $request_filename){ set $rule_3 2$rule_3; } if ($uri !~ ".*.(ico|gif|jpg|jpeg|png|js|css)"){ set $rule_3 3$rule_3; } if ($rule_3 = "321"){ rewrite ^/([^?]*) /index.php?_route_=$1 last; } } access_log off; expires max; location ~ [^/]\.php(/|$) { fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; if (!-f $document_root$fastcgi_script_name) { return 404; } fastcgi_param PHP_ADMIN_VALUE "sendmail_path = /usr/sbin/sendmail -t -i -f [email protected]"; fastcgi_pass unix:/var/www/php-fpm/ivan.sock; fastcgi_split_path_info ^((?U).+\.ph(?:p\d*|tml))(/?.+)$; try_files $uri =404; fastcgi_index index.php; include /etc/nginx/fastcgi_params; } }
- Не забуваємо поміняти: домен, IP та шляхи, перш ніж вставити в свій файл конфігурації.