Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx + Magento in subfolder

I had a look on the related topics here, but didn't do the trick for me. So here is what I'm doing. We are currently moving from one server to another. Old one was running Apache, new one is running Nginx. So for one of our websites we have a Wordpress CMS site on http://mydomain.com and an Magento Installation on http://mydomain.com/shop

CMS is running without problems. If it comes to the shop I'm stuck. The Magento index.php is shown - all good so far. But as soon as I try to navigate somewhere else in the shop I run into 404 errors. So must be some mistakes with the rewrites. I tried many things none works.

So here comes my current vhost configuration:

server {
listen               80;
listen              443;
server_name         www.domain.de domain.de *.domain.de;
root                /var/www/domain.de/www.domain.de/htdocs;
index       index.php;

access_log          /var/log/nginx/domain_access.log;
error_log           /var/log/nginx/domain_error.log;

error_page      403   /403.php;
error_page      404   /404.php;
error_page      500   /500.php;
error_page      501   /500.php;
error_page      502   /500.php;
error_page      503   /500.php;

location ~* \.(js|css|jpg|jpeg|gif|png|ico|swf)$ {
    if (-f $request_filename) {
      expires   30d;
      add_header Cache-Control "public";
      break;
    }
}

#Temp-Dateien blocken
location ~* \.(bak|cache|csv|git|old|php~|spool|svn|swp|temp|tmp)$ {
    deny all;
}

#Sonstige Dateien blocken
location ~* \.(1st|386|app|ani|asm|bat|bin|cfg|cmd|cnf|com|cpl|dbs|dll|drv|exe|inc|sh|lnk|reg|scr|sys|vxd)$ {
    deny all;
}

location / {
try_files $uri $uri/ /index.php?$args;
}

location /shop {
    index index.html index.php;
    try_files $uri $uri/ @handler;
    expires 30d;
}

location ~ ^/(app|includes|lib|media/downloadable|pkginfo|report/config.xml|var)/ { internal; }
location /var/export/ { internal; }
location /. { return 404; }
location @handler { rewrite /shop/ /index.php; }
location ~* .php/ { rewrite ^(.*.php)/ www last; }

location ~ ^/(gpack|img|tmp/map)/ {
   allow      all;
}

location ~ .*\.php?$ {
    fastcgi_pass             unix:/var/run/php/domain.de.sock;
    fastcgi_index            index.php;
include                  conf/fastcgi.conf;
}
}

any hints are welcome. I guess it must be a small mistake of mine.

Thanks in advance. Regards, Steven

like image 359
Steven Avatar asked Oct 02 '13 16:10

Steven


Video Answer


1 Answers

* Edit *

Ok I got it solved. Here is my current config file.

server {
listen               80;
listen              443;
server_name         www.domain.de domain.de *.domain.de;
root                /var/www/domain.de/www.domain.de/htdocs;
index       index.php;

access_log          /var/log/nginx/domain_access.log;
error_log           /var/log/nginx/domain_error.log;

error_page      403   /403.php;
error_page      404   /404.php;
error_page      500   /500.php;
error_page      501   /500.php;
error_page      502   /500.php;
error_page      503   /500.php;

location ~* \.(js|css|jpg|jpeg|gif|png|ico|swf)$ {
    if (-f $request_filename) {
      expires   30d;
      add_header Cache-Control "public";
      break;
    }
}


#Temp-Dateien blocken
location ~* \.(bak|cache|csv|git|old|php~|spool|svn|swp|temp|tmp)$ {
    deny all;
}

#Sonstige Dateien blocken
location ~* \.(1st|386|app|ani|asm|bat|bin|cfg|cmd|cnf|com|cpl|dbs|dll|drv|exe|inc|sh|lnk|reg|scr|sys|vxd)$ {
    deny all;
}

location / {
try_files $uri $uri/ /index.php?$args;
}

location /shop {
    index index.html index.php;
try_files $uri $uri/ @handler;
    expires 30d;
    if ($uri ~ "^/index.php/admin.*$"){
        rewrite ^/index.php/admin(.*) /admin$1 redirect;
    }
}

location ~ ^/shop/(app|includes|lib|media/downloadable|pkginfo|report/config.xml|var)/ { internal; }
location /shop/var/export/ { internal; }
location @handler { rewrite / /shop/index.php; }

location ~ ^/(gpack|img|tmp/map)/ {
   allow      all;
}

location ~ .*\.php?$ {
    fastcgi_pass             unix:/var/run/domain.de.sock;
    fastcgi_index            index.php;
include                  conf/fastcgi.conf;
}
}

hope it helps somebody else as well. Thanks for your support.

like image 139
Steven Avatar answered Sep 18 '22 22:09

Steven