13

Can OpenCart use SEO URLs on nginX? I understand that in Apache, it creates an .htaccess, but is it capable of automatically managing the URL redirection in nginX?

OC2PS
  • 1,037
  • 3
  • 19
  • 34

1 Answers1

22

OpenCart on Nginx - We have been using it for a year. Finally it seems other people starting to use it. Getting help is a nightmare and getting in on Nginx is tricky sometimes..

My www.site.com.vhost is below, example:

# FORCE WWW
server {
    server_name  site.com;
    rewrite ^(.*) http://www.site.com$1 permanent;
}
# MAIN SERVER
# NINX 0.8.54 - WORKS ON 1.1.19
server {
    server_name  www.site.com;
    listen 80;
    root /var/www/www.site.com/web;
    index index.php index.html;
    location /image/data {
        autoindex on;
    }
    location /admin {
        index index.php;
    }
    location / {
        try_files $uri @opencart;
    }
    location @opencart {
        rewrite ^/(.+)$ /index.php?_route_=$1 last;
    }
    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    # Make sure files with the following extensions do not get loaded by nginx because nginx would display the source code, and these files can contain PASSWORDS!
    location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_ {
        deny all;
    }
    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }
    location ~*  \.(jpg|jpeg|png|gif|css|js|ico)$ {
        expires max;
        log_not_found off;
    }
    location ~ \.php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

OK, now with regards to managing your site. You can now enable SEO via the admin, see my other posts tagged nginx and opencart for all the URLs and further customisation with the location / {}

I also recommend reading about removing the index.php?route= - link below:

Remove index.php?route=common/home from OpenCart

Community
  • 1
  • 1
TheBlackBenzKid
  • 26,324
  • 41
  • 139
  • 209
  • I would also be wary of the `audoindex on;` this is due to we use a CDN and it would be best to keep these folders private. – TheBlackBenzKid Mar 28 '13 at 11:26
  • Can you please elaborate your setup more in detail. I tried using your config, but it does not seem to work at all. I am missing backgroud information about your FastCGI setup etc. etc. – Julius F May 23 '13 at 18:25
  • Please post your own question @daemonfire300 as this setup does work. We use NGINX on all our OpenCart platform installs. `autoindex on` remove this, it is the equivalent of showing `index of / ` and listing all files... – TheBlackBenzKid May 28 '13 at 12:10