What is the problem with installation? Just use Apps magento 2 installer and install M2.1 and them upgade to M2.2.2 For me it works.I can get M2 running using nginx only.. but still working on the install process
Hi,
is someone knows working rewrite rules for Magento 2 using only nginx?
Thanks in advance
the problem is that theWhat is the problem with installation? Just use Apps magento 2 installer and install M2.1 and them upgade to M2.2.2 For me it works.
Which rewrite rules you are using?
It would be very interesting to know which settings in the directives you have, to get Magento 2.2 running as nxginx without proxy. Have tried different configurations. Unfortunately without success. It would be nice if someone would publish it. Thank you in advance.
<?php if (is_file($OPT['ssl'] ? $VAR->domain->physicalHosting->httpsDir .'/bin/magento': $VAR->domain->physicalHosting->httpDir .'/bin/magento')):?>
<?php if (is_file($OPT['ssl'] ? $VAR->domain->physicalHosting->httpsDir .'/bin/magento': $VAR->domain->physicalHosting->httpDir .'/bin/magento')):?>
### MAGENTO ROOT DIRECTORY RULE
set $MAGE_ROOT "<?php echo $OPT['ssl'] ? $VAR->domain->physicalHosting->httpsDir : $VAR->domain->physicalHosting->httpDir ?>";
root $MAGE_ROOT/pub;
<?php else: ?>
### PLESK ORIGINAL RULE
root "<?php echo $OPT['ssl'] ? $VAR->domain->physicalHosting->httpsDir : $VAR->domain->physicalHosting->httpDir ?>";
<?php endif ?>
location ~ (index|get|static|report|404|503|health_check)\.php$ { }
location ~ (index|get|static|report|404|503|health_check)\.php(/.*)?$ { }
if (!-e $request_filename){ rewrite ^(/.*)([^/]+/)$ /index.php$is_args$args last; }
index index.php;
autoindex off;
<?php if ($VAR->domain->physicalHosting->directoryIndex): ?>
location ~ /$ {
index <?=$VAR->quote($VAR->domain->physicalHosting->directoryIndex)?>;
}
location ~ /$ {
index "index.html" "index.cgi" "index.pl" "index.php" "index.xhtml" "index.htm" "index.shtml";
}
session.save_path=/var/www/vhosts/YOUR_DOMAIN_TLD/httpdocs/var/session
http://<shopurl>/<adminurl>/admin/backendapp/redirect/app/setup/
location ~ (index|get|static|report|404|503|health_check)\.php$ { }
location ~ (index|get|static|report|404|503|health_check)\.php(/.*)?$ { }
if you have enabled Plesk Mode Security DON'T use
Many thanks Igo for replying.
The changes you posted I already made in /opt/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php to change root and works fine.
The problem is in PLESK ONYX under Additional nginx directives: please see attachmentAdditional_nginx_directives.png
There I set the following directives: please see attachment nginx.conf.pdf
My MAGENTO 2.2.2 projekt can be found under: Home page
Homepage is working. If I click any link I get an 404. Same if I try to call the adminpanel.
Would be nice to get a answer whats wrong. Thanks in advance.
Regardes
Christian
server {
listen SERVER_IP:443 ssl http2;
server_name DOMAIN_TLD;
server_name www.DOMAIN_TLD;
server_name ipv4.DOMAIN_TLD;
ssl_certificate /usr/local/psa/var/certificates/;
ssl_certificate_key /usr/local/psa/var/certificates/;
ssl_client_certificate /usr/local/psa/var/certificates/;
set $MAGE_ROOT "/var/www/vhosts/DOMAIN_TLD/httpdocs";
root $MAGE_ROOT/pub;
index index.php;
autoindex off;
charset UTF-8;
error_page 404 403 = /errors/404.php;
access_log "/var/www/vhosts/system/DOMAIN_TLD/logs/proxy_access_ssl_log";
error_log "/var/www/vhosts/system/DOMAIN_TLD/logs/proxy_error_log";
location ~ ^/setup {
root $MAGE_ROOT;
location ~ ^/setup/index.php(/.*)?$ {
fastcgi_pass "unix:///var/www/vhosts/system/DOMAIN_TLD/php-fpm.sock";
fastcgi_split_path_info ^(/setup/index.php) (/.+)$;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=756M \n max_execution_time=600";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ ^/setup/(?!pub/). {
deny all;
}
location ~ ^/setup/pub/ {
add_header X-Frame-Options "SAMEORIGIN";
}
}
# PHP entry point for update application
location ~ ^/update {
root $MAGE_ROOT;
location ~ ^/update/index.php(/.*)?$ {
fastcgi_split_path_info ^(/update/index.php) (/.+)$;
fastcgi_pass "unix:///var/www/vhosts/system/DOMAIN_TLD/php-fpm.sock";
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
# Deny everything but index.php
location ~ ^/update/(?!pub/). {
deny all;
}
location ~ ^/update/pub/ {
add_header X-Frame-Options "SAMEORIGIN";
}
if (!-e $request_filename){ rewrite ^(/.*)(/.+)$ /index.php$is_args$args last; }
}
location @fallback {
return 404;
}
location / { try_files $uri $uri/ /index.php$is_args$args; }
location /pub/ {
location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) { deny all; }
alias $MAGE_ROOT/pub/;
add_header X-Frame-Options "SAMEORIGIN";
}
location /static/ {
# Uncomment the following line in production mode
# expires max;
# Remove signature of the static files that is used to overcome the browser cache
location ~ ^/static/version { rewrite ^/static/(version[^/]+/)?(.*)$ /static/$2 last; }
location ~ ^/(.*\.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2))$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires +1y;
log_not_found off;
access_log off;
add_header ETag "";
add_header Access-Control-Allow-Origin "www.DOMAIN_TLD, cdn.DOMAIN_TLD";
if (!-f $request_filename) { rewrite ^/static/?(.*)$ /static.php?resource=$1 last; }
}
location ~ ^/(.*\.(zip|gz|gzip|bz2|csv|xml))$ {
add_header Cache-Control "no-store";
add_header X-Frame-Options "SAMEORIGIN";
expires off;
log_not_found off;
access_log off;
add_header ETag "";
add_header Access-Control-Allow-Origin "www.DOMAIN_TLD, cdn.DOMAIN_TLD";
if (!-f $request_filename) { rewrite ^/static/?(.*)$ /static.php?resource=$1 last; }
}
if (!-f $request_filename) { rewrite ^/static/?(.*)$ /static.php?resource=$1 last; }
add_header X-Frame-Options "SAMEORIGIN";
}
location /media/ {
try_files $uri $uri/ /get.php$is_args$args;
location ~ ^/media/theme_customization/.*\.xml { deny all; }
location ~ ^/(.*\.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2))$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires +1y;
log_not_found off;
access_log off;
add_header ETag "";
add_header Access-Control-Allow-Origin "www.DOMAIN_TLD, cdn.DOMAIN_TLD";
try_files $uri $uri/ /get.php$is_args$args;
}
location ~ ^/(.*\.(zip|gz|gzip|bz2|csv|xml))$ {
add_header Cache-Control "no-store";
add_header X-Frame-Options "SAMEORIGIN";
expires off;
log_not_found off;
access_log off;
add_header ETag "";
add_header Access-Control-Allow-Origin "www.DOMAIN_TLD, cdn.DOMAIN_TLD";
try_files $uri $uri/ /get.php$is_args$args;
}
add_header X-Frame-Options "SAMEORIGIN";
}
location /media/customer/ { deny all; }
location /media/downloadable/ { deny all; }
location /media/import/ { deny all; }
location ~ (index|get|static|report|404|503|health_check)\.php(/.*)?$ {
try_files $uri =404;
add_header X-Config-By 'ProTech' always;
add_header X-Processing-Time $request_time always;
add_header X-Request-ID $request_id always;
add_header Strict-Transport-Security $hsts_header always;
add_header X-UA-Compatible 'IE=Edge,chrome=1';
add_header Link "<$scheme://$http_host$request_uri>; rel=\"canonical\"" always;
fastcgi_split_path_info ^((?U).+\.php) (/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass "unix:///var/www/vhosts/system/DOMAIN_TLD/php-fpm.sock";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_buffers 1024 4k;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=756M \n max_execution_time=18000";
fastcgi_read_timeout 1800s;
fastcgi_connect_timeout 1800s;
include /etc/nginx/fastcgi.conf;
}
location ~ /$ {
if (!-e $request_filename){ rewrite ^(/.*)([^/]+/)$ /index.php$is_args$args last; }
}
disable_symlinks if_not_owner from=$document_root;
add_header X-Powered-By PleskLin;
add_header X-Config-By 'ProTech';
include "/var/www/vhosts/system/DOMAIN_TLD/conf/vhost_nginx.conf";
}
server {
listen SERVER_IP:80;
server_name DOMAIN_TLD;
server_name www.DOMAIN_TLD;
server_name ipv4.DOMAIN_TLD;
return 301 https://$host$request_uri;
}
Good morning!
The following line I had to comment out because I get an error.
add_header Strict-Transport-Security $hsts_header always;
ERROR: Invalid nginx configuration: nginx: [emerg] unknown "hsts_header" variable nginx: configuration file /etc/nginx/nginx.conf test failed
Many thanks Igo. You saved hours of my life
map $scheme $hsts_header {
https 'max-age=15768000';
}
map $scheme $hsts_is_header {
https 'max-age=15768000; includeSubDomains; preload';
}
server {
..........
...........
}
map $scheme $hsts_header {
https 'max-age=15768000';
}
map $scheme $hsts_is_header {
https 'max-age=15768000; includeSubDomains; preload';
}
Good morning!
Now understanding that ROOT directive are not allowed or working in Additional nginx directives or includes.
I put the complete lines in /opt/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php
CHANGED: fastcgi_pass "unix:///var/www/vhosts/system/<?php echo $VAR->domain->asciiName ?>/php-fpm.sock";
Now MAGENTO 2.2.2 is running whitout problems on PLESK ONYX with NGINX (not in proxy mode).
The following line I had to comment out because I get an error.
add_header Strict-Transport-Security $hsts_header always;
ERROR: Invalid nginx configuration: nginx: [emerg] unknown "hsts_header" variable nginx: configuration file /etc/nginx/nginx.conf test failed
Many thanks Igo. You saved hours of my life
Good morning!
Now understanding that ROOT directive are not allowed or working in Additional nginx directives or includes.
I put the complete lines in /opt/psa/admin/conf/templates/custom/domain/nginxDomainVirtualHost.php
CHANGED: fastcgi_pass "unix:///var/www/vhosts/system/<?php echo $VAR->domain->asciiName ?>/php-fpm.sock";
Now MAGENTO 2.2.2 is running whitout problems on PLESK ONYX with NGINX (not in proxy mode).
The following line I had to comment out because I get an error.
add_header Strict-Transport-Security $hsts_header always;
ERROR: Invalid nginx configuration: nginx: [emerg] unknown "hsts_header" variable nginx: configuration file /etc/nginx/nginx.conf test failed
Many thanks Igo. You saved hours of my life
set $MAGE_ROOT "/var/www/vhosts/mysubdomain.tld/demo";
set $MAGE_MODE default; # or production or developer
#root $MAGE_ROOT/pub;
index index.php;
autoindex off;
charset off;
add_header 'X-Content-Type-Options' 'nosniff';
add_header 'X-XSS-Protection' '1; mode=block';
location /setup {
root $MAGE_ROOT;
location ~ ^/setup/index.php {
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ ^/setup/(?!pub/). {
deny all;
}
location ~ ^/setup/pub/ {
add_header X-Frame-Options "SAMEORIGIN";
}
}
location /update {
root $MAGE_ROOT;
location ~ ^/update/index.php {
fastcgi_split_path_info ^(/update/index.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
}
# deny everything but index.php
location ~ ^/update/(?!pub/). {
deny all;
}
location ~ ^/update/pub/ {
add_header X-Frame-Options "SAMEORIGIN";
}
}
location / { try_files $uri $uri/ /index.php$is_args$args; }
location ~ /$ {
if (!-e $request_filename){ rewrite ^(/.*)([^/]+/)$ /index.php$is_args$args last; }
}
location /pub {
location ~ ^/pub/media/(downloadable|customer|import|theme_customization/.*\.xml) {
deny all;
}
alias $MAGE_ROOT/pub;
add_header X-Frame-Options "SAMEORIGIN";
}
location /static/ {
if ($MAGE_MODE = "production") {
expires max;
}
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires +1y;
if (!-f $request_filename) {
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
}
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
add_header Cache-Control "no-store";
add_header X-Frame-Options "SAMEORIGIN";
expires off;
if (!-f $request_filename) {
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
}
if (!-f $request_filename) {
rewrite ^/static/(version\d*/)?(.*)$ /static.php?resource=$2 last;
}
add_header X-Frame-Options "SAMEORIGIN";
}
location /media/ {
try_files $uri $uri/ /get.php?$args;
location ~ ^/media/theme_customization/.*\.xml {
deny all;
}
location ~* \.(ico|jpg|jpeg|png|gif|svg|js|css|swf|eot|ttf|otf|woff|woff2)$ {
add_header Cache-Control "public";
add_header X-Frame-Options "SAMEORIGIN";
expires +1y;
try_files $uri $uri/ /get.php?$args;
}
location ~* \.(zip|gz|gzip|bz2|csv|xml)$ {
add_header Cache-Control "no-store";
add_header X-Frame-Options "SAMEORIGIN";
expires off;
try_files $uri $uri/ /get.php?$args;
}
add_header X-Frame-Options "SAMEORIGIN";
}
location /media/customer/ {
deny all;
}
location /media/downloadable/ {
deny all;
}
location /media/import/ {
deny all;
}
location ~ cron\.php {
deny all;
}
location ~ (index|get|static|report|404|503|health_check)\.php(/.*)?$ {
try_files $uri =404;
fastcgi_param PHP_FLAG "session.auto_start=off \n suhosin.session.cryptua=off";
fastcgi_param PHP_VALUE "memory_limit=256M \n max_execution_time=600";
fastcgi_read_timeout 600s;
fastcgi_connect_timeout 600s;
fastcgi_param MAGE_MODE $MAGE_MODE;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location / { try_files $uri $uri/ /index.php$is_args$args; }
location ~ /$ {
if (!-e $request_filename){ rewrite ^(/.*)([^/]+/)$ /index.php$is_args$args last; }
}
if (!-e $request_filename){ rewrite ^(/.*)([^/]+/)$ /index.php$is_args$args last; }
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
please pay attention to your links@FrancYescO I tried your config in the nginx directives in Plesk and I got the pages to load but I am unable to figure out how to get the static files like css png jpg and js files to load. Attached is a file containing the nginx config. I contact Plesk for support and they told me to contact Magento. Their support is a joke even though I pay for the license directly.
Any help would be appreciated.