Nginx rewrite rules for Magento

Hoe krijgt u een Magento website werkend onder NGINX met DirectAdmin ?

 
Normaliter maakt Magento gebruik van htaccess om bijvoorbeeld permalinks goed te kunnen laten door lopen, echter htaccess werkt niet onder NGINX, daarvoor hebben wij "rewrite"
 
Hieronder leg ik u uit hoe u "rewrite" kunt toepassen op uw DirectAdmin met NGINX server.
Hierbij ga ik vanuit dat NGINX al draait op uw DirectAdmin server, anders moet u eerst deze HOWTO volgen!
 
U moet root toegang hebben tot de DirectAdmin server:
 
Ga naar:  /usr/local/directadmin/data/users/USER/nginx.conf:
Voeg daar onderstaande regels toe:
 
}
 
    ## These locations would be hidden by .htaccess normally
    location ^~ /app/                { deny all; }
    location ^~ /includes/           { deny all; }
    location ^~ /lib/                { deny all; }
    location ^~ /media/downloadable/ { deny all; }
    location ^~ /pkginfo/            { deny all; }
    location ^~ /report/config.xml   { deny all; }
    location ^~ /var/                { deny all; }
 
    location /var/export/ { ## Allow admins only to view export folder
        auth_basic           "Restricted"; ## Message shown in login window
        auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
        autoindex            on;
    }
 
    location  /. { ## Disable .htaccess and other hidden files
        return 404;
    }
 
    location @handler { ## Magento uses a common front handler
        rewrite / /index.php;
    }
 
    location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
        rewrite ^(.*.php)/ $1 last;
    }
 
    location ~ .php$ { ## Execute PHP scripts
        if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
 
        expires        off; ## Do not cache dynamic content
        fastcgi_pass   127.0.0.1:9000;
        #fastcgi_param  HTTPS $fastcgi_https;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
        fastcgi_param  MAGE_RUN_TYPE store;
        include        fastcgi_params; ## See /etc/nginx/fastcgi_params
    }
 
zie als voorbeeld, en doe het op deze manier:
 
server
{
 
 
listen 84.243.229.111:80;
 
 
server_name magento.vservs.com www.magento.vservs.com;
 
access_log /var/log/nginx/domains/magento.vservs.com.log;
access_log /var/log/nginx/domains/magento.vservs.com.bytes bytes;
error_log /var/log/nginx/domains/magento.vservs.com.error.log;
 
 
root /home/magento/domains/magento.vservs.com/public_html;
  
index index.php index.html index.htm;
 
 
# use fastcgi for all php files
location ~ \.php$
{
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
 
if (-f $request_filename)
{
fastcgi_pass unix:/usr/local/php53/sockets/magento.sock;
}
}
 
    ## These locations would be hidden by .htaccess normally
    location ^~ /app/                { deny all; }
    location ^~ /includes/           { deny all; }
    location ^~ /lib/                { deny all; }
    location ^~ /media/downloadable/ { deny all; }
    location ^~ /pkginfo/            { deny all; }
    location ^~ /report/config.xml   { deny all; }
    location ^~ /var/                { deny all; }
 
    location /var/export/ { ## Allow admins only to view export folder
        auth_basic           "Restricted"; ## Message shown in login window
        auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword
        autoindex            on;
    }
 
    location  /. { ## Disable .htaccess and other hidden files
        return 404;
    }
 
    location @handler { ## Magento uses a common front handler
        rewrite / /index.php;
    }
 
    location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler
        rewrite ^(.*.php)/ $1 last;
    }
 
    location ~ .php$ { ## Execute PHP scripts
        if (!-e $request_filename) { rewrite / /index.php last; } ## Catch 404s that try_files miss
 
        expires        off; ## Do not cache dynamic content
        fastcgi_pass   127.0.0.1:9000;
        #fastcgi_param  HTTPS $fastcgi_https;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param  MAGE_RUN_CODE default; ## Store code is defined in administration > Configuration > Manage Stores
        fastcgi_param  MAGE_RUN_TYPE store;
        include        fastcgi_params; ## See /etc/nginx/fastcgi_params
    }
 
 
Klik op save:
in console: #service nginx restart
En je Magento website werkt onder DirectAdmin met NGINX!:


Was this article helpful?

mood_bad Dislike 2
mood Like 0
visibility Views: 16259